[CentOS] Any one have a good example...

Johnny Hughes mailing-lists at hughesjr.com
Tue Aug 29 19:51:21 UTC 2006


On Tue, 2006-08-29 at 15:25 -0400, mike.redan at bell.ca wrote:
> Something like this works alright:
> 
> 
> # Check if process is running already
> SCRIPT_NAME=do_stuff
> pidfile=/tmp/$SCRIPT_NAME.pid
> 
> 
> if [ -f $pidfile ]; then
>    runpid=`cat $pidfile`
>    if ps -p $runpid; then
>       echo "$SCRIPT_NAME is already running ... stopping"
>       exit 1
>    else
>       echo "$SCRIPT_NAME pid found but process dead, cleaning up and
> starting ..."
>       rm -f $pidfile
>    fi
> else
>    echo "No $SCRIPT_NAME Process Detected ... starting"
> fi
> 
> echo $$ > $pidfile
> 

Maybe I am being dense here ... BUT ...

Doesn't the "echo $$" only happen AFTER the else process is finished ???

if you make the "else" process be the rsync script, then it will not
create $pidfile until after the rsync is done ... which does not help
you.

if you leave the else process as is and kick off the rsync after the
echo $$ then it is not the same PID that you wrote to the $pidfile and
you will start more than one rsync process ... as the PID that you wrote
to $pidfile as the echo process ... that already finished ... or I am
mistaken?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.centos.org/pipermail/centos/attachments/20060829/a7cd504b/attachment.sig>


More information about the CentOS mailing list