I use this parallel call to do something as user postgres via passwordless ssh access of user root:
parallel -q -j0 ssh {} -l root "sudo -u postgres -i psql -tAc
\"select current_user, current_database()\" -d \$(echo {}| cut -d@ -f1) "
::: db_foo@host1 db_bar@host2 ...
... it works except for hosts running older linux systems.
I get this message from old system:
psql: warning: extra command-line argument "current_database()" ignored
psql: FATAL: Peer authentication failed for user "current_user,"
Versions:
- GNU bash, Version 4.1.10(1)
- Sudo version 1.7.6p2
How to get the quoting right to get this working on old linux systems?
Update
With the quoting from the answer of Paul A Jungwirth, this result happens:
===> parallel -q -j0 ssh {} -l root "echo \$BASH_VERSION; rpm -qf /usr/bin/sudo; sudo -u postgres -i psql -tAc '\"select current_user, current_database()\"' -d \$(echo {}| cut -d@ -f1); echo " ::: ...
4.2.53(1)-release
sudo-1.8.6p3-3.13.1.x86_64
ERROR: syntax error at or near ""select current_user, current_database()""
ZEILE 1: "select current_user, current_database()"
^
4.1.10(1)-release
sudo-1.7.6p2-0.16.1.x86_64
psql: warning: extra command-line argument "current_database()"" ignored
psql: FATAL: Peer authentication failed for user "current_user,"
.... I guess I will give up and use two loops. The first to scp a script, the second to call this script.
parallelis just going to make things worse. Consider putting your command into a script instead so that you can avoid needing to muck about with quotes on the command line.sudoto allow a regular user to run the desiredpsqlcommand without a password, rather than logging in as root just to avoid typing a password for thesudocommand.parallel -q -j0 psql -h {} '...'.