Find the answer to your Linux question:
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.
  1. #1
    Just 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.

  2. #2
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    have you tried to look for it with
    Code:
    ps aux | grep dar
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  3. #3
    scm
    scm is offline
    Linux 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.

  4. #4
    Just 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 ?

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Code:
    echo $$ >/tmp/mypid
    Easy!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •