I have a script that reads a file containing a list of server names. It's suppose to loop through the list of names and execute a command on the remote server using ssh. It processes the ssh command for the first server in the list and then exits. Here's the code:
#!/bin/bash
FILENAME=server_list.txt
cat $FILENAME | while read LINE
do
echo "$LINE"
# Run the Users.sh script on the remote server
ssh root@$LINE '/usr/local/bin/Users.sh > /root/UserAccounts.txt'
done
When I comment out the ssh command the script processes as expected. Does ssh do something when it exits the first time that is maybe stopping the rest of the script from processing? I'd appreciate any suggestions.
---------- Post updated at 05:20 PM ---------- Previous update was at 04:28 PM ----------
I found the answer. Gotta use the -n option in the ssh command
ssh -n root@$LINE '/usr/local/bin/Users.sh > /root/UserAccounts.txt'