Executing ssh command in a bash shell script withi

2019-01-15 04:24发布

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?

标签: bash ssh
1条回答
Summer. ? 凉城
2楼-- · 2019-01-15 04:56

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

查看更多
登录 后发表回答