> > I know how to set-up a crontab for the begining of the month, but
> > how do you do it for the last day of the month? 31?
> > TIA
How about writing a script that alters your crontab on the first day of
the month(or any early time in the month) to change the last day of the
month line. In about 10 minutes I whipped up:
$lastwk=`cal \`date +"%m %Y"\` | tail -2 | head -1`;
## This gets the last two chracters of the lastwk string.
## Notice when assigning them to lastday I switch the order
## It's like a stack....ooooh.....aaaah
## Get the old crontab so we can preserve what you already have and
## Change only what needs to be changed
open (CURRCRON, "crontab -l |");
## We're opening a temporary crontab file in tmp, feel free to store it
## in your home directory or something to make sure no one can cat it
## during the split second that it will exist.
open (NEWTEMPCRON, "|/tmp/tmpcronfile");
## The regular expression in this if has to match the command you wanna
## run on the last day of the month...so make it good
print NEWTEMPCRON $_;}
print "0 0 $lastday * * /your/last/day/of/month/command\n";}
## Update your crontab with the contents of the temp file and deletes
## the temp file
print "I fixed your crontab, have a happy day!\n";
###########End Perl Script
I tried to comment in the logic and steps I'm using in english. It
should be pretty straight forward if you know perl and the comments are
there for those who don't and not to insult your intelligence;) Some
changes you might wanna make is to include full path names for the
system calls(Stuff that is between the ` `(back tics) so as to avert
running trojan horse versions of cal, date, head, tail, and crontab.
It's not pretty but it does the job. Not bad for 10 minutes work.
P T Z
Piotr T Zbiegiel
Unix Systems Specialist
Berk & Hirt Consulting Co.