0

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

mikeghen

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?

1 Answer 1

6

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .