daemon - bash script to monitor myself -
i need develop shell script not started if instance of them self running. if build test.sh monitors need know if running , abort, otherwise (if not running) can run #!/bin/bash loop() { while [ 1 ]; echo "run"; #-- (... omissis ...) sleep 30 done } daemon="`/bin/basename $0`" pidlist=`/usr/bin/pgrep $daemon | grep -v $$` echo "1:[ $pidlist ]" pidlist=$(/usr/bin/pgrep $daemon | grep -v $$) echo "2:[ $pidlist ]" echo "3:[ `/usr/bin/pgrep $daemon | grep -v $$` ]" echo "4:[" /usr/bin/pgrep $daemon | grep -v $$ echo "]" if [ -z "$pidlist" ]; loop & else echo "process $daemon running pid [ $pidlist ]" fi exit 0; when run above script first time (no previous instances running) output: 1:[ 20341 ] 2:[ 20344 ] 3:[ 20347 ] 4:[ ] i cannot understand why 4th attempt not return (as expected). what's wrong in script? have ...