Re: OT: Linux Interview Questions



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



Relevant Pages

  • Re: OT: Linux Interview Questions
    ... executes them sequentially as long as none of them fail, ... return a 1 and the whole statement will fail. ... Copy Bunny into your signature to help him on his ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • RE: drive space shell script help ?
    ... > # You have to get rid of the word 'Capacity' or your comparison will ... > will fail. ... > Got a computer with idle CPU time? ... To unsubscribe, ...
    (freebsd-questions)
  • Re: Outsiders observation upon the pros and cons of Debian
    ... approach to getting your way to a worldwide audience. ... and seen acrimonious responses from camps ... I fail to see how someone who makes no demands is ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Re: eth* devices (again)
    ... If eth0 is taken by something, you cannot assign it again by such rules, so all of them will fail. ... But the wireless card broke badly at that point. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Migrate from K7 to AMD64-K8
    ... I have searched Google and the archive, but not found what I am looking ... I understand all that stuff about install and chroot a 32/64 bit partition. ... But I fail to find hints on a clean migration path for my Sarge 32-bit ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)