Bash if and or conditionals -
i have perl script runs in cron , if script fails run leaves behind lock file prevent script run again.
i'm trying run bash script checks if process running , checks see if lock file left behind
if processes running , lock file exists exit 0;
if process not running , lock file exists rm lockfile. exit 0;
if process not exist , lock file 'not present' exit 0;
i've been checking if process exists running ps ax |grep -v grep |grep process.pl
i'm looking conditionals in bash should running here.
thanks
the process.pl
should write process id lockfile, wihch common pattern. can write following code:
if [ -f "$lockfile" ]; pid=$(cat "$lockfile") if kill -0 "$pid"; : "running normally" else : "terminated somehow" rm -f "$lockfile" fi fi
Comments
Post a Comment