From owner-freebsd-questions@FreeBSD.ORG Wed Jul 18 04:53:35 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 61B3816A404 for ; Wed, 18 Jul 2007 04:53:35 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout4.cac.washington.edu (mxout4.cac.washington.edu [140.142.33.19]) by mx1.freebsd.org (Postfix) with ESMTP id 3E0FD13C442 for ; Wed, 18 Jul 2007 04:53:35 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.33.9] (may be forged)) by mxout4.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.06) with ESMTP id l6I4rSoq021258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 Jul 2007 21:53:28 -0700 X-Auth-Received: from [192.168.10.45] (c-24-10-12-194.hsd1.ca.comcast.net [24.10.12.194]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l6I4rMJZ012955 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 17 Jul 2007 21:53:27 -0700 Message-ID: <469D9CC2.4040902@u.washington.edu> Date: Tue, 17 Jul 2007 21:53:22 -0700 From: Garrett Cooper User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: Fredrik Tolf References: <000f01c7c56d$da44d640$0200a8c0@satellite> <200707160427.l6G4Rb5q090225@banyan.cs.ait.ac.th> <469AFA30.4050504@u.washington.edu> <200707180233.l6I2XJrw097658@banyan.cs.ait.ac.th> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.3.2.304607, Antispam-Engine: 2.5.1.298604, Antispam-Data: 2007.7.17.213032 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __STOCK_PHRASE_7 0, __USER_AGENT 0' Cc: freebsd-questions@freebsd.org Subject: Re: cron job every 5 hours 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, 18 Jul 2007 04:53:35 -0000 Fredrik Tolf wrote: > Olivier Nicole writes: > > >>> Something like: >>> >>> minute */5 * * * root path/to/scriptname >>> >>> will do the trick. >>> >>> Substitute the * in */5 for your desired start time (* being 0). >>> >>> -Garrett >>> >>> PS crond won't do 5 hours and every x number of minutes per job (5 hours >>> + x mins from end to start), just a flat amount of time (5 hours apart >>> from start to start). If you need that type of 'precision', at will >>> solve that like Olivier said if you place it at the end of the command. >>> >> I am afraid not. >> >> */5 means on every hours that is a multiple of 5, not every five >> hours. So it will run every day at hour 0, 5, 10, 15 and 20. Between >> hour 20 one day and hour 0 the next day there is only 4 hours, not >> the "every 5 hours" requested. >> That's what I meant >_>.. >> Just to confirm that I launched a cron job yesterday: >> >> 23 */5 * * * /home/java/on/crontest >> >> It ran at 15:23, 20:23 and today at 0:23 and 5:23 and so on: >> >> Date: Wed, 18 Jul 2007 05:23:00 +0700 (ICT) >> From: Olivier Nicole >> To: on@banyan.cs.ait.ac.th >> Subject: test crontab 5 hours >> X-Virus-Scanned: on CSIM by amavisd-milter (http://www.amavis.org/) >> >> This is a test for crontab >> [...] >> Only way to run a job every 5 hours is with at(1). >> > > I wouldn't go as far as saying the *only* way. You could make the cron > job run every hour and then have an internal check in it (or using a > wrapper script that checks it). Kind of like this, maybe? > > #!/bin/sh > unset nogo > if [ -r /tmp/lastrun ]; then > now=`date +%H` > if [ $((($now + 24 - `cat /tmp/lastrun`) % 24)) -lt 5 ]; then > nogo=y > fi > fi > > if [ "$nogo" = y ]; then exit 0; fi > > date +%H >/tmp/lastrun > > # Do real work here > If you're going to do it that way, just try something like this: #!/bin/sh while [ 1 ]; do exec command; sleep 1900 # 5 hours => 5*3600; done and set it up as an rc script :). Shell scripts with sleep won't give you exactly the 5 hours you desire, but should come close (within 1-5 seconds of actual time depending on your host PC's precision, and whether or not your RTC battery is dead ;)..). -Garrett