Date: Sat, 12 Jun 2010 08:17:18 -0400 From: jhell <jhell@dataix.net> To: Alexander Leidinger <Alexander@leidinger.net> Cc: fs@freebsd.org Subject: Re: Do we want a periodic script for a zfs scrub? Message-ID: <4C137ACE.9080900@dataix.net> In-Reply-To: <20100611104219.51344ag1ah7br4kk@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> <AANLkTilech-Onkawu4pvNQx5hrByd3R-Mn6MK4AiSHsc@mail.gmail.com> <4C1138D0.7070901@dataix.net> <20100611104219.51344ag1ah7br4kk@webmail.leidinger.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On 06/11/2010 04:42, Alexander Leidinger wrote: : #!/bin/sh : : lastscrub=$(zpool history exports |grep scrub |tail -1 |cut -f1 -d.) : todayjul=$(date -j -f "%Y-%m-%d" "+%j" $(date "+%Y-%m-%d")) : scrubjul=$(date -j -f "%Y-%m-%d" "+%j" $lastscrub) : : echo $lastscrub Last Scrub From zpool history : echo $todayjul Today converted to julian : echo $scrubjul Last scrub converted to julian : : expired=$(($todayjul-$scrubjul)) > > Apart from the fact that we can do this with one $(( ))... what happens > if/when time_t is extended to 64 bits on 32 bit platforms? Can we get > into trouble with the shell-arithmetic or not? It depends upon the > bit-size of the shell integers, and the signedness of them. Jilles (our > shell maintainer) suggested also to use the seconds since epoch and I > asked him the same question. I'm waiting for an answer from him. > I do not think this would be a problem for the script as the script is relying on date for the conversion except for the subtraction that is taking place. If there was a problem then I would believe it would have to be corrected in date(1) & possibly sh(1), I could be wrong though. > The same concerns apply to test(1) (or the corresponding buildin) in the > solution of Artem. > I agree. > By calculating with days everywhere (like in my solution), I'm sure that > it takes longer to hit a wall than by calculating with seconds since > epoch (which can cause a problem in 2038 or during a transition when > this problem is tackled in time_t but not here, which is not that far > away). The off-by-one day once every 4 years shouldn't be a problem. If > someone can assure with some nice facts, that using the seconds since > epoch will not cause problems in the described cases, I have no problem > to switch to use them. I agree with this, please see corrected example above. Another situation that had come to mind is when & certainly being possible that the time on the system could drop to before the last scrub has taken place causing (using the above script for example) todayjul to be less than scrubjul and in that case would output a negative integer that would skew results until the system time has been restored to its correct & current date & time. if [ $todayjul -gt $scrubjul ]; then expired=$(($todayjul-$scrubjul)) else expired=$(($scrubjul-$todayjul)) fi -- jhell
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C137ACE.9080900>