[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cron bash date



* David Z Maze (dmaze@debian.org) [030801 07:13]:
> Lance Hoffmeyer <lance@augustmail.com> writes:
> 
> > I am trying to run a bash script in cron.  I originally wanted
> > it to run at 11:59pm on the last day of every month.  February
> > will always cause problems because of leap years.  Therefore,
> > I decided to run cron on the first day of every month using
> > the @month parameter.
> 
> crontab(5) doesn't suggest a good way to do this, no.  So yeah,
> running early (say, 12:03 AM) on the first of the month is easy:
> 
>   3 0 1 * * /usr/local/sbin/ourscript
> 
> > The problem is that I want the month to reflect the previous month.
> >
> > MON=$((`date +%m`-1))
> 
> How about:
> 
>   MON=`date -d yesterday +%m`

Oh yeah, I forgot about that, duh! =p  That's way cleaner than my daily
touching a file idea.

> date(1) seems to think "yesterday" is exactly 24 hours ago, if you're
> looking at other fields.  (Or maybe it's exactly a day ago; this makes
> a difference around daylight savings.)

date actually understands a pretty wide array of expressions.  So if
"yesterday" isn't to your liking, you can also use $(date -d "24 hours
ago").  Also, I think the OP will then easily see how to have a script
running early on the first of the month can give the date of 23:59
yesterday, by, say, running at 00:05 and asking date for "6 minutes
ago".

good times,
Vineet
-- 
http://www.doorstop.net/
-- 
						--Nick Moffitt
A: No.
Q: Should I include quotations after my reply?

Attachment: signature.asc
Description: Digital signature


Reply to: