oxidworks
oxidworks

Reputation: 1642

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' "

Upvotes: 1

Views: 726

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246403

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.

Upvotes: 1

Related Questions