0

I'm try to make some shell script work like below.

 #!/bin/bash while [ 1 ] do pid=`ps -ef | grep "sample.exe" | grep -v 'grep' | awk '{print $2}'` if [ -z $pid ]; then nohup ./run.sh > /dev/null & #./run.sh is shell script for run 'sample.exe' file fi usage=`ps -ef | grep "sample_watcher.sh" | grep -v 'grep' | awk '{print $2}'` if [ -z $usage ]; then $kill $(ps aux | grep "sample_watcher.sh"| awk '{print $2}') fi sleep 5 done "sample_watcher.sh" 15L, 491C 

this sh = "sample_watcher.sh". and this will work find sample.exe is runnig or not.

and if not running, then start run.sh = start up 'sample.exe'

and last part

if "sample_watcher.sh"is already run. then kill "sample_watcher.sh".

only one "sample_watcher.sh" should be run.

Is there better way to do?

Thanks.

2
  • Search for "bash lock" or "bash execution lock", there are several similar questions you might find helpful. Commented Apr 13, 2017 at 4:37
  • Besides flock there's also watershed. Commented Apr 13, 2017 at 4:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.