From owner-freebsd-questions@FreeBSD.ORG Wed Sep 3 10:37:56 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A3E01106566B for ; Wed, 3 Sep 2008 10:37:56 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from betty.computinginnovations.com (mail.computinginnovations.com [64.81.227.250]) by mx1.freebsd.org (Postfix) with ESMTP id 3C6BC8FC13 for ; Wed, 3 Sep 2008 10:37:53 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from p28.computinginnovations.com (dhcp-10-20-30-100.computinginnovations.com [10.20.30.100]) (authenticated bits=0) by betty.computinginnovations.com (8.14.2/8.14.2) with ESMTP id m83AbjaY070832; Wed, 3 Sep 2008 05:37:45 -0500 (CDT) (envelope-from derek@computinginnovations.com) Message-Id: <6.0.0.22.2.20080903053036.025d11d8@mail.computinginnovations.com> X-Sender: derek@mail.computinginnovations.com X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Wed, 03 Sep 2008 05:37:34 -0500 To: ElihuJ , freebsd-questions@freebsd.org From: Derek Ragona In-Reply-To: <19272656.post@talk.nabble.com> References: <19272656.post@talk.nabble.com> Mime-Version: 1.0 X-Antivirus: avast! (VPS 080902-0, 09/02/2008), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: ClamAV 0.93.3/8145/Wed Sep 3 01:00:57 2008 on betty.computinginnovations.com X-Virus-Status: Clean X-ComputingInnovations-MailScanner-Information: Please contact the ISP for more information X-MailScanner-ID: m83AbjaY070832 X-ComputingInnovations-MailScanner: Found to be clean X-ComputingInnovations-MailScanner-From: derek@computinginnovations.com X-Spam-Status: No Content-Type: text/plain; charset="us-ascii"; format=flowed X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: Cron Question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2008 10:37:56 -0000 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.