All I want from this script is to ssh to the host, and check if the process is alive, and if it is not, I want the littel script to die. Does not die though. It stops, and then starts up again on the ssh is successful again. I want death though.
#!/bin/bash
iterate=0
while [ $iterate -le 20000 ]
do
rc=$?
ssh -q -T coolhost "ps -ef | egrep '[i]cool-process' | grep wrapper "
if [[ $rc -eq 0 ]] ; then
sleep 2
iterate=$((iterate+1 ))
else
break
exit 1
fi
done
It will iterate to 2000, however if the remote process breaks, it will not die. It will not break and exit.
this will work - but won't sleep - if I put a sleep the rc goes to 0 and is never dies. so this works but is too basic.
#!/bin/bash
set -e
while : ; do
ssh -q -T coolhost "ps -ef | egrep '[i]cool-process' | grep wrapper" > /dev/null 2>&1
done
ps -ef | grep ..., usepgrep. This is a much more direct way to search for processes by name (note useful options like-uand-fwhich you may want or need). It will return a failure code if the process is not found.rc=$?should be on the line followingssh...