Results 1 to 5 of 5
Hi,
I have written a script called by crontab which automaticaly create a complete backup and then differential backups (using dar) if they are not found on the system.
Now ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-02-2005 #1Just Joined!
- Join Date
- Jul 2005
- Location
- Switzerland
- Posts
- 24
Testing for a processus running
Hi,
I have written a script called by crontab which automaticaly create a complete backup and then differential backups (using dar) if they are not found on the system.
Now while the complete backup is running I would like to prevent starting incremental backups. how can I test if dar is running ? I looked for the ps command but could not find anything.
- 10-02-2005 #2
have you tried to look for it with
Code:ps aux | grep dar
- 10-09-2005 #3Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
You could get your script to create a temporary file containing its PID on starting (having first tested that the file doesn't exist. If it does, kill -0 the PID in the file to see if the process still exists, to guard against the script havingbeen killed without cleaning itself up). If all's clear, the script can run. Delete the file on exit.
- 10-09-2005 #4Just Joined!
- Join Date
- Jul 2005
- Location
- Switzerland
- Posts
- 24
That should be a good way, but how do you get the PID of the running script ?
I tried test `ps aux | grep -c "dar "` -ge 2 but it does not seems to always work, sometimes returning false while dar is actually running.
The only problem I see with "semaphore" idea is that I actually have 3 backups scripts registered in crontab and I want only one to be running at a time, not to overload the system (I now, I could set different time at the scripts...). All 3 scripts could use the same file, but what if a script does not terminate normally and do not erase the file. Then I could test for file date, but in this case I could endup with days without backups.
May be you have a further suggestion ?
- 10-09-2005 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Easy!Code:echo $$ >/tmp/mypid

To test it (assuming /tmp/mypid exists)
Code:if kill -0 $(</tmp/mypid) then echo job running else echo job not running fi


Reply With Quote
