Executing on remote server terminates while loop
Bash script looks like
#!/bin/bash local_command1 while read line; do local_command2; ssh remotesrv "somecommand"; done< /tmp/file /tmp/file has multiple lines but if I run as above the script stops after reading only first line. Commenting out ssh remotesrv "somecommand"; makes while loop read entire file as intended. I suspect it's something with having to connect to remote shell that breaks the loop but am not sure. Please let me know what I am doing incorrectly. |
Does the script stop and you are back and the command line prompt or does your script just hang?
Can you connect to the remote server using ssh from the command line? Are you using ssh keys? |
Quote:
|
(Please use [code][/code] tags.)
The reason your script stops is because the ssh command reads from stdin, which means it reads all the rest of your /tmp/file on the first run. You can solve this by redirecting or using the -n option. Code:
ssh remotesrv "somecommand" < /dev/null Code:
-n Redirects stdin from /dev/null (actually, prevents reading from |
ntubski . thank YOU! I think this helped.
|
All times are GMT -5. The time now is 06:14 PM. |