Date: Wed, 03 Sep 2008 05:37:34 -0500 From: Derek Ragona <derek@computinginnovations.com> To: ElihuJ <chinocubus@yahoo.com>, freebsd-questions@freebsd.org Subject: Re: Cron Question Message-ID: <6.0.0.22.2.20080903053036.025d11d8@mail.computinginnovations.com> In-Reply-To: <19272656.post@talk.nabble.com> References: <19272656.post@talk.nabble.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 SENDTO=me@mydomain.com 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 "freebsd-questions-unsubscribe@freebsd.org" > >-- >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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6.0.0.22.2.20080903053036.025d11d8>