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: http://www.nabble.com/Cron-Question-tp19272656p19272656.html
Sent from the freebsd-questions mailing list archive at Nabble.com.

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:

=============================================================
#!/usr/local/bin/ksh
# uncomment the following line for debugging
#set -x


RUNNING_FILE=RUNNING_FILE=/tmp/my_cronjob_running
LOGFILE=LOGFILE=/tmp/my_cronjob.log
[EMAIL PROTECTED]
MAIL=/usr/bin/mail
TOUCH=/usr/bin/touch
RM=/bin/rm


# 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;
        fi
}

function got_signal {
  echo "Got a signal" >> $LOGFILE
  epilog
  exit
}


# 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"
else
        $TOUCH $RUNNING_FILE
        $RM $LOGFILE
        $TOUCH $LOGFILE
#       add your job to be done here . . .
#
        epilog
fi

=============================================================

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

--
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.

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to