Re: Time Calculations in Shell
On 2008-03-16, Erwin Lindemann wrote:
>
> Suppose there is a file, f.
>
> Is it possible to calculate every date (in YYYY-MM-DD format) that
>
> a) falls between the last modification date of f and the current time, and
> b) is a certain day of the week, say Wednesday or Saturday
>
> in sh?
>
> The idea is, I want to call a program with YYYY-MM-DD as parameter with
> YYYY-MM-DD being every Saturday and Wednesday since the last time the
> script was run.
>
> In C, I'd probably start with the start date in seconds since the epoch,
With GNU date, that is available using the %s specifier.
> check what day of week it is and add number of seconds till desired day of
> week and then number of seconds in a week until we're in the future.
>
> Can something like that be done in a shell script?
>
> (preferably POSIX, but GNU should also be available on the target machine)
Try the date arithmetic section of the FAQ:
<http://cfaj.freeshell.org/shell/cus-faq.html#6>
Also, Chapter 8 of my book, which is online at
<http://cfaj.freeshell.org/shell/ssr/08-The-Dating-Game.shtml>
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
|