# apt-get install procmailEasy.
Here's a useful snippet of code using lockfile in a shell script:
#!/bin/sh LOCKFILE="/tmp/processname.lock" # Break the lock if locking process has died RUNNING_PID=`cat $LOCKFILE 2>/dev/null`; if [ "x"$RUNNING_PID != "x" ] ; then RUNNING_NAME=`ps -p $RUNNING_PID -o comm= 2>/dev/null`; if [ "x"$RUNNING_NAME != "processname.sh" ] ; then rm -f $LOCKFILE fi fi # Acquire lock lockfile $LOCKFILE echo $$ > $LOCKFILE echo whatever i am doing and plop in a log `date` >> /var/log/processname.log ...snip... echo whatever i am doing is completed `date` >> /var/log/processname.log # Release the lock rm -f $LOCKFILEIf you're doing a scad of stuff, rotate your logs by placing an appropriately named file in logrotate.d:
/var/log/processname.log /var/log/ohlookanotherprocessname.log { rotate 7 daily missingok notifempty compress sharedscripts endscript }
No comments:
Post a Comment