- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- run crontab at last day of month
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2007 03:14 PM
тАО09-04-2007 03:14 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2007 03:38 PM
тАО09-04-2007 03:38 PM
Solution---------------------------------
#!/usr/bin/sh
export PATH=${PATH}:/usr/local/bin
typeset -i STAT=0
if [[ $(caljd.sh -M) != $(caljd.sh -M -n 1) ]]
then
echo "It's the last day of the month; do your thing"
STAT=${?}
fi
exit ${STAT}
-----------------------------------------
Essentially, this compares the month of today with the month of tomorrow and if they differ, it's the last day of the month. Caljd.sh will work on leap years and across year boundaries. Invoke as caljd.sh -u for full usage and many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2007 03:53 PM
тАО09-04-2007 03:53 PM
Re: run crontab at last day of month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2007 04:04 PM
тАО09-04-2007 04:04 PM
Re: run crontab at last day of month
And much similar you could execute in that script this perl one-liner:
#perl -e 'exit ((localtime)[4] != (localtime(time+86400))[4])'
Next test $?
If it is 1 then it is the last day as the month now (4th element in tm array) was not equal to the month for the time now + a day worth of seconds.
If it is 0 then exit and wait for re-run.
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2007 07:53 PM
тАО09-04-2007 07:53 PM
Re: run crontab at last day of month
if [ "$(TZ=GMT-24 ; date +\%d)" = "01" ]
then
execute-script
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2007 12:17 AM
тАО09-05-2007 12:17 AM
Re: run crontab at last day of month
You can also leverage the 'cal' utility. To find the last day of the current month simply do:
DAY=$(cal|awk 'END{print DAY};{if (NF<1) {next};DAY=$NF}')
if [ ${DAY} -eq $(date +%m) ]; then
echo "end-of-month"
else
echo "not last day"
fi
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2007 11:49 PM
тАО09-05-2007 11:49 PM
Re: run crontab at last day of month
why not use the old but good cal?
HH MM * * * [[ $(cal) = *$(date +%d) ]] && /path/to/script
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2007 05:34 PM
тАО09-06-2007 05:34 PM
Re: run crontab at last day of month
[[ $(cal) = *$(date +%d) ]]
Pretty clever!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-20-2007 08:13 PM
тАО09-20-2007 08:13 PM
Re: run crontab at last day of month
Sometimes we are searching very complex solution while an easy UNIX command is available.
My mentor always said me: RTFM!
Rgds,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2007 04:35 AM
тАО09-21-2007 04:35 AM
Re: run crontab at last day of month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2007 07:05 AM
тАО09-21-2007 07:05 AM
Re: run crontab at last day of month
Ingenious work indeed Art!!!
Would help if you would enlighten the likes of me on its usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2007 09:21 AM
тАО09-21-2007 09:21 AM
Re: run crontab at last day of month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2007 03:05 PM
тАО09-21-2007 03:05 PM
Re: run crontab at last day of month
If you look at it, it is pretty obvious. ;-)
[[ $(cal) = *$(date +%d) ]]
Take the output from cal(1) and do a pattern match. Make sure that it matches the pattern "*current-day". The only time the current day matches the end of the line is the last day of the month. (Or if you have an evil locale, with one digit day of month, the 1st, or 8th and 9th for Feb.)-:
To fix that, use $(date +%2d)
>Bob: I was sure that the embedded newlines would block that
I'm not sure there are any when you use $().
Using the following shows them replaced by whitespace:
$ echo $(cal) > file
>Ben: schedule that cron job to run at 00:01 on the FIRST day of the month. I've found this is usually adequate.
I was going to suggest something similar but the process may need to be done in the middle of the day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2007 04:07 PM
тАО09-21-2007 04:07 PM
Re: run crontab at last day of month
... and often what is really meant by the "last day of the month" is really the last working day of the month (ie not a weekend and not a holiday) which becomes just a few extra arguments for caljd.sh.
if [[ $(caljd.sh -M) -ne $(caljd.sh -n 1 -x 6 -x 0 -h -M) ]]
then
echo "Today's the last working day of the month."
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2007 09:55 PM
тАО09-21-2007 09:55 PM
Re: run crontab at last day of month
First of all, I don't see any real reason not move all "last-day-of-a-month" jobs to the first day of a month, I fully agree with Ben Dehner here.
BTW, it seems, some of Olimpians in a similar previous thread proposed the following trick:
argus:/# (date; export TZ=GMT-24 ; date)
Sat Sep 22 11:44:53 IST 2007
Sun Sep 23 09:44:53 GMT 2007
You can play with TZ expression in date +%m command and compare it's output:
if [ $(date +%m) -ne $(export TZ=GMT-24 ; date +%m)]; then
echo "This is the last day of the month
fi
HTH