• Post Reply Bookmark Topic Watch Topic
  • New Topic

crontab  RSS feed

 
Jason Crest
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a little dilema with crontab. I have a script that needs to run at the end of each month, it must run only once. However, i do not know how to do this since some months have 30 days and some have 31, and february having twenty...something or other.
would a crontab command with
59 23 30,31 * command
be ok? If so, how would it account for february.
Thanks...
 
Chris De Vries
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that's fine, it just wouldn't run in February, and it would run twice in months with 31 days. Also you need another "*" for the day of the week. Why not do something like:

which runs one minute into the first of every month.
[ September 08, 2003: Message edited by: Chris De Vries ]
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,
But I would do this:

This runs every month from 28th to 31 but first it checks if the 'Next Day' will be the 1st.
If you don't have the fancy date version you can use perl to get the next day:
perl -le 'print scalar ((localtime (time + 60 * 60 * 24))[3])'
This prints out the next day and in turn you'd modify the above command to:
test $(perl -le 'print scalar ((localtime (time + 60 * 60 * 24))[3])') -eq 1 && run_your_month_end_report
Ugly, but it works!
 
Chris De Vries
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow... that's a good one.
Chris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!