|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Musing upon cron and end of the month
It is dead simple to schedule a job in cron to run on the 1st day of the month but ... how would you go about scheduling a job to run on the last day of each month?
This is just in the way of being a 'though experiment' as I have no need to do it, just curious about how it may be approached by different people.
__________________
According to Sod's Law, buttered toast lands butter side down, when dropped. Per nature, cats always land on their feet. So, what happens when you strap buttered toast to the back of a cat and throw it out a window?. |
|
#2
|
|||
|
|||
|
I would remove the logic from cron and put it into a shell script/program that cron runs. Basically you'd have it run either every day or at least on the 28th, 29th, 30th, and 31st of each month. cron is at least smart enough to be able to do that. Your program would then have the logic to do the right thing. It might need some sort of look up table to know how many days are in the current month/year combination. If the program determines that it is the last day of the month then it runs. Otherwise it just exits.
cron really doesn't handle something like this very well.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums. |
|
#3
|
||||
|
||||
|
Yes, that would be my route too ... now, next part: how to do the logic in the script? (Just general approach).
|
|
#4
|
|||
|
|||
|
here is the logic,
Code:
date '+%m %Y %d' | read mon year date
if [ `cal $mon $year | grep -v ^$ | tail -1 | awk '{print $NF}'` -eq $date ]
then
echo "Run the program"
else
echo "Do not run the program"
fi
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Musing upon cron and end of the month |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|