开发者

Executing ssh command in a bash shell script within a loop [duplicate]

This question already has answers here: in my bash loop over a list of some servers, if the ssh connects the bash script exits 开发者_StackOverflow社区 (2 answers) Closed 8 years ago.

I'm trying to execute an ssh command within a a bash shell script that should perform the following: 1) ssh to host 2) execute command 3) print value of command 4) repeat steps 1 -3 5) exit bash shell script

I have set up password less entry to the remote host, added host key to remote host

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

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

I do the following in the 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 each time through the loop another input string is read from the input text file and the request is made to the remote host. However, what I experience is that after the first request the script terminates. Am I correct to assume that as the first request is sent it creates a child process and once that process completes my script completes and the next turn through the loop is not executed?


ssh is consuming stdin. Pass it -n to prevent this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜