script running ssh commands (via loop) exiting after first iteration
Hello everyone,
One of my servers needs to issue an "apt-get update" command on each of the clients in a lab. However, after the first update, it exits. In trying to replicate the problem with a simpler script, I created the following which fetches the listings of multiple directories from a client: NUM=0 cat paths | while read DIR; do ssh server-name ls $DIR > /tmp/$NUM.txt NUM=`expr $NUM + 1` done Again, after the first iteration, the script exists. I tried the following line too, but it made no difference: bash -c ssh server-name ls $DIR > /tmp/$NUM.txt The only thing that worked so far is this xterm -e ssh server-name ls $DIR > /tmp/$NUM.txt Of course, this is far from ideal since a GUI gets involved. Any thoughts? Thanks much. |
To achieve this :
Quote:
Code:
#!/bin/bash And about Quote:
|
The problem is that the standard input of your local shell becomes the standard input of the remote command. This is the way ssh works. Every time the remote command terminates, ssh sends a SIGTTIN signal to the local shell, which results in terminating the standard input of the loop. To prevent this behaviour, you can try the -n option of ssh, that explicitly redirects the standard input from /dev/null, leaving the standard input of the local shell untouched.
|
Quote:
|
All times are GMT -5. The time now is 10:04 PM. |