Re: OT: Linux Interview Questions
- From: Douglas Allan Tutty <dtutty@xxxxxxxxxxxxx>
- Date: Fri, 16 Mar 2007 09:59:44 -0400
On Fri, Mar 16, 2007 at 01:16:46AM +0200, Atis wrote:
[snip]
00 06 * * * [ `date -d tomorrow +%d` -eq '01' ] && /the/script
for 6:00 AM on the last day of each month
[snip]
when you have multiple commands on a line with && between them, it
executes them sequentially as long as none of them fail, IOW so long
as they return 0. the [ ... ] is the 'test' command and it tests the
statement inside the brackets and returns a 0 if the statement is
true. if its false (i.e. `date -d tomorrow +%d` is '02') then it will
return a 1 and the whole statement will fail.
Damn, so this is just a cheat, as the actual command is
[ `date -d tomorrow +%d` -eq '01' ] && /the/script
and it will be executed every day..
Yes its a cheat. The correct answer is that having __cron__ run
something only on the last day of a month is impossible. Cron itself
runs every minute of every day. I guess any type of alarm clock has to
run at intervals equal to its granularity. A wall clock tics every
second for example.
Personally, I find bash scripting very cryptic and I don't mean that as
a compliment to bash. If I had to run a command on the last day of the
month I would just write a Python script that did this kind of testing
and have it run as part of cron.daily.
Doug.
--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx
- References:
- Re: OT: Linux Interview Questions
- From: Jim Hyslop
- Re: OT: Linux Interview Questions
- From: Jim Hyslop
- Re: OT: Linux Interview Questions
- From: Tarek Soliman
- Re: OT: Linux Interview Questions
- From: Jim Hyslop
- Re: OT: Linux Interview Questions
- From: Bernd Prager
- Re: OT: Linux Interview Questions
- From: Tarek Soliman
- Re: OT: Linux Interview Questions
- From: Tarek Soliman
- Re: OT: Linux Interview Questions
- From: Jorge Peixoto de Morais Neto
- Re: OT: Linux Interview Questions
- From: Andrew Sackville-West
- Re: OT: Linux Interview Questions
- From: Atis
- Re: OT: Linux Interview Questions
- Prev by Date: Re: how to print unicode encoded file to ps
- Next by Date: Re: Running Debian with kernel from other distro....
- Previous by thread: Re: OT: Linux Interview Questions
- Next by thread: Re: OT: Linux Interview Questions
- Index(es):
Relevant Pages
|