Skip to content
Advertisement

bash list postgresql databases over ssh connection

I am doing some work on a remote Postgresql database.

When I log into the server this command works on bash: $ psql -c “l”

Remote login over ssh is possible using:

ssh user@server -C "cd /tmp && su postgres -c psql"

But why doesn’t it work from this command?

ssh user@server -C " cd /tmp && su postgres -c psql -c 'l' "
→   bash: l: command not found

This is working, also “psql -l” but I don’t understand why I have to use backslash 3 times here?

ssh user@server -C " cd /tmp && su postgres -c 'psql -c \l' "

Advertisement

Answer

Use several levels of quoting:

ssh user@server -C "cd /tmp && su postgres -c 'psql -c "\l"'"

The double backslash is not strictly necessary since l is no recognized escape sequence.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement