Cron Question

Derek Ragona derek at
Wed Sep 3 10:37:56 UTC 2008

At 10:45 AM 9/2/2008, ElihuJ wrote:

>Hi all. I have a question about cron jobs that seem to be running to long or
>with multiple copies of itself. For example, I have a backup script that I
>run that seems to make multiple copies of itself. If I view the running
>processes I see numerous instances of the same cron job. Is there something
>I can do to limit this from happening? When it does, it drains my CPU and
>some of my other processes are non responsive. Any help would be
>appreciated. Thank you.
>View this message in context: 
>Sent from the freebsd-questions mailing list archive at

For longer running jobs I do a couple things.  I use a file to be sure only 
one instance is running, but I also add signal handling.  The following is 
written for ksh, but can be adapted to sh if needed:

# uncomment the following line for debugging
#set -x

SENDTO=me at

# Print an epilog string and clear the RUNNING_FILE
function epilog {
   echo "We are all done scanning." >> $LOGFILE
         $MAIL -s "MyCronjob Report" $SENDTO < $LOGFILE
         if [ -f $RUNNING_FILE ]; then
                 $RM $RUNNING_FILE;

function got_signal {
   echo "Got a signal" >> $LOGFILE

# Here pointers to signal handling subroutines are set
trap got_signal TERM HUP INT QUIT

if [ -f $RUNNING_FILE ]; then
         echo "mycronjob is already running"
         $RM $LOGFILE
         $TOUCH $LOGFILE
#       add your job to be done here . . .


>freebsd-questions at mailing list
>To unsubscribe, send any mail to "freebsd-questions-unsubscribe at"
>This message has been scanned for viruses and
>dangerous content by MailScanner, and is
>believed to be clean.

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

More information about the freebsd-questions mailing list