One obvious source of error is that 'ps aux' is not portable - it only works with GNU ps. It will not, for example, work on Solaris, or on Windows. Take a look at Proc::ProcessTable instead, which supports the most common Unix variants - still no Win32 support though.
The approach taken by rsnapshot (backup software; needs to be safe and reliable) is to drop a PID file somewhere - the default is /var/run/rsnapshot.pid - and look for that when starting up. If it already exists, we read it to get the PID of the process that may be hanging around, and then try to send it a signal. If we can successfully send it a signal (ie, if a process with that PID exists) we log that, and stop. If there is no such process, then whether to continue or not is configurable.
This is safe - it guarantees that (provided nothing else messes with the PID file!) you won't have two instances of rsnapshot running at once. And it's *failsafe* because if rsnapshot exits without cleaning up the PID file *and* that PID is in use by something else next time rsnapshot runs, it still won't run. Better to miss a backup than to potentially have two backups fighting each other and screwing up.
In reply to Re: How can i check my script is already running?
by DrHyde
in thread How can i check my script is already running?
by shekarkcb
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |