I have a shell script that I'm working on that uses pssh to get the user id of a user on a remote server:

for USER in $(cat users.txt); do
    runuser -l mike -c 'pssh -H server.mike.com -o /home/mike/output id -u $USER'
    cat /home/mike/output/server.mike.com

The file users.txt contains one line


When I run my script, I get an error:

[1] 14:23:15 [FAILURE] server.mike.com Exited with error code 1\

But, when I run the command:

runuser -l mike -c 'pssh -H server.mike.com -o /home/mike/output id -u mikeghen'

I don't get the error:

[1] 13:11:53 [SUCCESS] server.mike.com

I feel like this has something to do with a question I asked before, Why is permission denied during pssh?, and so I tried wrapping my command in quotes with no luck. Any suggestions?


The '' quotes prevent variable interpolation. Use "" instead.

host:~ sven$ echo $USER
host:~ sven$ echo '$USER'
host:~ sven$ echo "$USER"
  • Thanks, this is exactly what I needed. A suggestion for anyone else reading this: running your script using bash -x – Mike Mar 9 '15 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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