bash - restart program if it outputs some string -
i want loop process in bash script, process should run forever fails.
when fails, outputs >>747;3r
last line, keeps running.
i tried (just testing)
while [ 1 ] mono program.exe last_pid=$! sleep 3000 kill $last_pid done
but doesn't work @ all, process mono program.exe
runs forever (until crashes, script nothing.)
$! expands pid of last process started in background. can seen with:
cat test sleep 2 lastpid=$! echo $lastpid ~$ bash -x test + sleep 2 + lastpid= + echo
vs
~$ cat test sleep 2 & lastpid=$! echo $lastpid :~$ bash -x test + lastpid=25779 + sleep 2 + echo 25779
the fixed version of script read:
while true; mono program.exe & last_pid=$! sleep 3000 kill $last_pid done
your version running mono program.exe , sitting there. didn't make next line waiting process finish. kill command didn't work $! never populated (wasn't background process).
Comments
Post a Comment