Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Jun 2010 09:34:49 -0700
From:      Artem Belevich <fbsdlist@src.cx>
To:        Alexander Leidinger <Alexander@leidinger.net>
Cc:        fs@freebsd.org
Subject:   Re: Do we want a periodic script for a zfs scrub?
Message-ID:  <AANLkTilech-Onkawu4pvNQx5hrByd3R-Mn6MK4AiSHsc@mail.gmail.com>
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> <AANLkTin445x53XTprCkn1ISmVrnJeSu1XhR52tmtUfkS@mail.gmail.com> <20100610173825.164930ekkryr5tes@webmail.leidinger.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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
<Alexander@leidinger.net> wrote:
> Quoting Artem Belevich <fbsdlist@src.cx> (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
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTilech-Onkawu4pvNQx5hrByd3R-Mn6MK4AiSHsc>