From owner-freebsd-fs@FreeBSD.ORG Thu Jun 10 16:34:55 2010 Return-Path: Delivered-To: fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EDECF106564A for ; Thu, 10 Jun 2010 16:34:54 +0000 (UTC) (envelope-from artemb@gmail.com) Received: from mail-gw0-f54.google.com (mail-gw0-f54.google.com [74.125.83.54]) by mx1.freebsd.org (Postfix) with ESMTP id 9BB0A8FC19 for ; Thu, 10 Jun 2010 16:34:54 +0000 (UTC) Received: by gwj20 with SMTP id 20so107585gwj.13 for ; Thu, 10 Jun 2010 09:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=MC3I8FcxLBDFrRWpwq2eEV8tx9Qr4iji8o+RECRnV6g=; b=r7Dv6Qemf8ZgBMDM3eyTWmVO45hQ1Bez4+dhe45fXUQWcLL5bjCp/uAuZnvWM1zhcu 3+lN5+8nzzXsMS/3sHtYq5H8uOg9q7JC2IUJ56L+FlK5aLilLzbItizm3yiypORJaMPf RmhNvNmOyXtLWj/tu2qPWZJKLXuQJx70torhk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=L6sLqT5vh7HYYn07viZ8RSlR+s747bFHiMAtuAaDz+4Ta46vcc/OZ+E8vIQEPCrNyp +s7yTHMox7L4mAgzQMDPPWpNzYarBw2W1I7iSiXNeMcoTP8DO24rejc+AHaef7nF2GD5 L0w0HxMaZBnm5976PRgoLptA+jgNLoOvskRV8= MIME-Version: 1.0 Received: by 10.229.214.8 with SMTP id gy8mr341769qcb.173.1276187689283; Thu, 10 Jun 2010 09:34:49 -0700 (PDT) Sender: artemb@gmail.com Received: by 10.220.202.11 with HTTP; Thu, 10 Jun 2010 09:34:49 -0700 (PDT) In-Reply-To: <20100610173825.164930ekkryr5tes@webmail.leidinger.net> References: <20100609162627.11355zjzwnf7nj8k@webmail.leidinger.net> <4C0FAE2A.7050103@dataix.net> <4C0FB1DE.9080508@dataix.net> <20100610115324.10161biomkjndvy8@webmail.leidinger.net> <20100610173825.164930ekkryr5tes@webmail.leidinger.net> Date: Thu, 10 Jun 2010 09:34:49 -0700 X-Google-Sender-Auth: -vohyxI_OHLBoDB5mmJ_vCo_cfE Message-ID: From: Artem Belevich To: Alexander Leidinger Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: fs@freebsd.org Subject: Re: Do we want a periodic script for a zfs scrub? X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jun 2010 16:34:55 -0000 You can do something like this: #SCRUB_TS=3D"2010-06-08.20:51:12" SCRUB_TS=3D$1 # parse timestamp, move it forward by 1 month and print in seconds since Ep= och NEXT_SCRUB_DATE_S=3D`date -j -f "%Y-%m-%d.%H:%M:%S" -v+1m +"%s" $SCRUB_TS` # for debugging purposes convert epoch time into something human-readable NEXT_SCRUB_DATE=3D`date -r $NEXT_SCRUB_DATE` # surrent time in secs since Epoch. NOW_S=3D`date +"%s"` # Compare two times to figure out if next scrub time is still in the future if [ $NOW_S -gt $NEXT_SCRUB_DATE_S ]; then echo yup. else echo nope. fi --Artem On Thu, Jun 10, 2010 at 8:38 AM, Alexander Leidinger wrote: > Quoting Artem Belevich (from Thu, 10 Jun 2010 07:59:46 > -0700): > >>> Good idea! I even found a command line which does the calculation for t= he >>> number of days between "now" and the last run (not taking a leap year >>> into >>> account, but an off-by-one day error here does not matter). >> >> You can get exactly one month difference by using -v option of 'date' >> command to figure out the time/date offset by arbitrary amount. >> Combined with +"%s" format to print number of seconds since Epoch and >> -r to specify the reference point in time it makes 'date' pretty >> useful in scripts. > > What we have is the date of the last scrub (e.g. 2010-06-08.20:51:12), an= d > what we want to know is if between the last scrub and now we passed a > specific amount of days or not. > > What I do is taking the year multiplied with 365 plus the day of the year= . > Both of this for the last date of the scrub and "now". The difference is = the > number of days between those two dates. This value I can use with -le or = -ge > for the test command. > > This is only off by one once in a leap year when the leap-day is in-betwe= en > the two dates (those people which want to scrub every 4 years are off by = two > when both leap-days are in-between, but a scrub of every 4 years or more > looks unreasonable to me, so I do not care much about this). > > This is done in one line with two calls to date (once for the last scrub, > once for "now") and a little bit of shell-buildin-arithmetic. If you have= a > more correct version which is not significantly more complex, feel free t= o > share it here. > > Bye, > Alexander. > > -- > =A0"Who would have though hell would really exist? And that it would be i= n New > Jersey?" -Leela > "Actually..." - Fry > > http://www.Leidinger.net =A0 =A0Alexander @ Leidinger.net: PGP ID =3D B00= 63FE7 > http://www.FreeBSD.org =A0 =A0 =A0 netchild @ FreeBSD.org =A0: PGP ID =3D= 72077137 >