Crontab - End of Month

Crontab - End of Month

Post by Thom Theriaul » Thu, 15 May 1997 04:00:00



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

--
 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Thom Theriault - Computing & Media Services
Information Systems - Syracuse University
 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

 
 
 

Crontab - End of Month

Post by bill davids » Thu, 15 May 1997 04:00:00




| 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?

You can run a better cron daemon, but that's no practical at some
sites. Here's a general solution:

0 0 28 2 *                      /usr/local/bin/do_it
0 0 30 4,6,9,11 0               /usr/local/bin/do_it
0 0 31 1,3,5,7,8,10,12 *        /usr/local/bin/do_it

This is ugly, hopefully someone has something prettier.
--

"As a software development model, Anarchy does not scale well."
                -Dave Welch

 
 
 

Crontab - End of Month

Post by Jeff Gyurk » Thu, 15 May 1997 04:00:00


This is a multi-part message in MIME format.

--------------3DA3B652637
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


> 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

> --
>  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> Thom Theriault - Computing & Media Services
> Information Systems - Syracuse University
>  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

X X 30 4,6,9,11 /dir/dira/scriptname
X X 31 1,3,5,7,8,10,12 /dir/dira/scriptname

You can do the same for February
--
_____________________________________________________________________
Jeff Gyurko
Sr. Unix System Administrator
Citibank
New York, NY


                To talk to me, change DOT to .

Any comments or statements made are not necessarily those of
Citicorp, its subsidiaries or affiliates.

"http://www.missingkids.org"
Have a look, you never know who you might find.

--------------3DA3B652637
Content-Type: image/gif; name="hysm.gif"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="hysm.gif"

<encoded_portion_removed>
Ow==
--------------3DA3B652637--

 
 
 

Crontab - End of Month

Post by Seagu » Thu, 15 May 1997 04:00:00


:
: 0 0 28 2 *                      /usr/local/bin/do_it
: 0 0 30 4,6,9,11 0               /usr/local/bin/do_it
: 0 0 31 1,3,5,7,8,10,12 *        /usr/local/bin/do_it
:
: This is ugly, hopefully someone has something prettier.

You can always set your system clock ahead 24 hours and schedule it
for the first day of the month.  :D

Cheers,
-+JLS

:)  <--- this post is smiley-captioned for the humor-impaired

--


http://www.aracnet.com/~seagull   \        (seize the guinea pig!)

 
 
 

Crontab - End of Month

Post by Andrew Dunst » Thu, 15 May 1997 04:00:00


this should be an FAQ :-)

i am not sure why anyone REALLY needs to do this, but I wrote a one
line perl script a while back to solve it:

#!/usr/local/bin/perl5 -w
# lastday.pl
exit ((localtime($now=time))[4] == (localtime($now+86400))[4]);

now you put in your crontab something like:

0 2 28,29,30,31 * * lastday.pl && do_whatever_you_want

cheers

andrew

: 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

: --
:  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
: Thom Theriault - Computing & Media Services
: Information Systems - Syracuse University
:  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

--

-------------------------------------------------------------------------
  There's nothing either good or bad, but thinking makes it so - Hamlet
  http://www.gr-lakes.com/~andrew (including PGP key)
  PGP Key fingerprint = 5C 44 7D E4 76 A3 31 DE  3D 11 FA 15 4D 87 1F 5E
-------------------------------------------------------------------------

 
 
 

Crontab - End of Month

Post by Jan Tellkam » Fri, 16 May 1997 04:00:00



> 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

do you really need the last day of the month?
can't you use the 28th d.o.m.?

--
Jan Tellkamp
Flensburg, 14. Mai 1997

Old programmers never die.
They just branch to another adress.

Per the FCA, this email address may not be added to
any commercial mail list
(Note: bogus e-mail address - remove the leading x)

 
 
 

Crontab - End of Month

Post by Emanuele D'Arrig » Fri, 16 May 1997 04:00:00



> 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?

Use three crontab lines on the same crontab call.

crontab
mm hh 31 1,3,5,7,8,10,12 * /usr/local/shells/rockerduck.csh
mm hh 30 4,6,9,11 *  /usr/local/shells/rockerduck.csh
mm hh 28 2 *  /usr/local/shells/rockerduck.csh
<CTRL-D>

where mm and hh are minutes and hours for the start.

As you can notice, it doesn't works for years having
a 29 feb day.

Hope it is useful...

Ciao Ciao!

Manu

 
 
 

Crontab - End of Month

Post by Piotr T Zbiegie » Fri, 16 May 1997 04:00:00



> > 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:

#!/usr/bin/perl

$lastwk=`cal \`date +"%m %Y"\` | tail -2 | head -1`;
chop($lastwk);

## 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
$tmp=chop($lastwk);
$lastday=chop($lastwk).$tmp;

## 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");

while(<CURRCRON>){

## 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
if(!/your_reg_exp/){
print NEWTEMPCRON $_;}
else{
print "0 0 $lastday * * /your/last/day/of/month/command\n";}

Quote:}

close CURRCRON;
close NEWTEMPCRON;

## Update your crontab with the contents of the temp file and deletes
## the temp file
`crontab /tmp/tmpcronfile`;
unlink("/tmp/tmpcronfile");

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.  

Good Luck
        P T Z

--
Piotr T Zbiegiel
Unix Systems Specialist
Berk & Hirt Consulting Co.

 
 
 

Crontab - End of Month

Post by Steffen Klu » Sat, 17 May 1997 04:00:00




Quote:>[...]
>X X 30 4,6,9,11 /dir/dira/scriptname
>X X 31 1,3,5,7,8,10,12 /dir/dira/scriptname

>You can do the same for February

Can you? What would it look like?

Cheers
Steffen.

--

Fujitsu Australia Ltd
Keywords: photography, Mozart, UNIX, Islay Malt
--

 
 
 

Crontab - End of Month

Post by Steffen Klu » Sat, 17 May 1997 04:00:00


Actually, I think the cleanest way of achieving that is putting all
'candidate' last days (28..31) into one crontab line and precede
the actual command with some script checking whether tomorrow is
the first or not (letting the system's calendar work for you):

x x 28,29,30,31 x x tomorrow_is_first.sh && do_it

This may break only if called immediately before midnight. But hey,
you could do ...tomorrow_is_first_or_second.sh && do_it. That would
be `close-to-midnight'-safe.

Hope this helps
Steffen.

--

Fujitsu Australia Ltd
Keywords: photography, Mozart, UNIX, Islay Malt
--

 
 
 

Crontab - End of Month

Post by Eric v/d Me » Sun, 18 May 1997 04:00:00





> >[...]
> >X X 30 4,6,9,11 /dir/dira/scriptname
> >X X 31 1,3,5,7,8,10,12 /dir/dira/scriptname

> >You can do the same for February

> Can you? What would it look like?

> Cheers
> Steffen.

> --

> Fujitsu Australia Ltd
> Keywords: photography, Mozart, UNIX, Islay Malt
> --

How about:

X X 28 2 /dir/dira/scriptname
0 0 1 1 echo please check the crontab entry for february

You will get mail on the first of january to remind.

Eric

 
 
 

1. Crontab field 3, day of month, 1-31, what if month has 30 days?

The 3rd field of a crontab entry specifies 'what day of the month' as a value
in the range 1-31.  Let's say I have:

0 0 31 1-12 * /usr/local/adm/End_Of_Month_Script

What happens when the month has less than 31 days?  Is the cron job
ignored or does cron figure it out and run it.

Thanks for any help.  (BTW, I do not want to run the script at midnight
of the 1st day, it must be done on the last day of the month).

--

Jeff Blaine

CIESIN Operations

2. Performance difference between UDMA33 and UDMA66

3. bad day of months message from crontab . Why ?

4. SUMMARY: Reading SG-written DAT-tapes? Still a problem...

5. crontab entry for the 1st Monday of the month

6. How to RECOMPILE KERNEL (step by step)

7. crontab, specify last day of month?

8. Is perl Version 5.X available?

9. How would you setup a crontab for 1st and 3rd Sat of each month?

10. crontab - last day of month

11. crontab: last day of every month

12. crontab last day of month

13. crontab: last day of every month