SSH scripting question

crazycaveman

n00b
2FA
Joined
Sep 20, 2008
Messages
17
I'm trying to set up a script to update the passwd file nightly on a Linux machine for NIS. In order to do this, I have to get the details from a 2nd machine through SSH. I have tried running the following command to no avail:
Code:
cat /tmp/users.lst | ssh user@server "while read username; do getent passwd $username >> /shared/folder/passwd.tmp; done"
and
Code:
ssh user@server "while read username; do getent passwd $username >> /shared/folder/passwd.tmp; done </shared/folder/users.lst"
However, it seems that the output of the cat command is not being piped over to the SSH session; the passwd.tmp file will be full of the "standard" users (root, ntp, etc.). I have tried putting the users.lst file on the shared folder and it still won't work. Would anyone have some idea on how to do this?
 
I found where my problem was. I was using double quotes (") instead of single quotes(') for the ssh command. This caused the client shell to interpret the $username and then pass run it in ssh. I stupidly forgot about this...
 
Back
Top