Running an ssh command in a bash shell script in a loop

I am trying to execute the ssh command in a bash shell, which should do the following: 1) ssh to host 2) execute the command 3) print the value of the command 4) repeat steps 1 -3 5) exit the bash shell script

I set a less password on the remote host, added the host key to the remote host

I want to check the various states of the httpd process on a remote host In the httpd_process.txt text file, I have:

/etc/init.d/httpd (stop, start, restart)

I do the following in a script:

while read LINE do echo "Httpd Request: $LINE" status=`$LINE` echo "Status: $status" sleep 5 # sleep so that next done < /path_name/httpd_process.txt exit 0 

I assumed that every time a different input line is read from the input text file through the loop, and the request is made to the remote host. However, what I'm experiencing is that after the first request, the script terminates. Do I correctly assume that when sending the first request, it creates a child process, and as soon as this process ends, my script ends and the next loop run fails?

+4
source share
1 answer

ssh consumes stdin. Skip it -n to prevent this.

+12
source

All Articles