On my CentOS 7 machine, I am running this command:

pssh -h rephosts -i "/bin/getent hosts sync.$(hostname) | awk '{ print $1 }'"

but I am only getting my host ip (where i am executing this command) response from all servers.

I have added entries for hosts in my /etc/hosts file in all machines.

I want all the servers to respond with their ip address respectively.


$(hostname) is evaluated on your local host, before the pssh command is started. You can solve this by escaping the $:

pssh -h rephosts -i "/bin/getent hosts sync.\$(hostname) | awk '{ print \$1 }'"
  • yes, thanks for the answer. Also I have to put another \ after the print \$1. – Ted Khi Dec 7 '18 at 10:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.