SrikantRajeev
asked on
Cron Script
I want to run cron job script in my linux server.
The job should restart my linux server at the end of every month at around 24:00 hrs.
Let me know how should i configure the cron job for this requirement.
The job should restart my linux server at the end of every month at around 24:00 hrs.
Let me know how should i configure the cron job for this requirement.
with cron, it may be simpler to schedule the job to run at the beginning of every month at 00:00 hrs.
crontab entry for 1st day of month:
0 0 1 * * /sbin/shutdown -r now
0 0 1 * * /sbin/shutdown -r now
0 0 * * * if [[ $(date +'%d') -eq $(cal | awk '!/^$/{ print $NF }' | tail -1) ]]; then /sbin/reboot; fi;
http:#a38395901 seems to restart 24 hours earlier than requested
ASKER
so which is the right syntax i need to use
Well, this will determine if it's the last day of the month:
if ! [ "$(/bin/date -d "`/bin/date` + 1 day" +%m)" == "$(/bin/date -d "`/bin/date`" +%m)" ]; then echo "reboot, last day"; fi;
But http://#a38394375 will reboot on the first day of the month at 00:00 -> this is the 'last' day of the month, right? :)
if ! [ "$(/bin/date -d "`/bin/date` + 1 day" +%m)" == "$(/bin/date -d "`/bin/date`" +%m)" ]; then echo "reboot, last day"; fi;
But http://#a38394375 will reboot on the first day of the month at 00:00 -> this is the 'last' day of the month, right? :)
24:00 hrs on the last day of the month is the same as 00:00 hours on the first day of the month
@ozo - that's what I mean ;)
If you run the cron job at 00:00 hours on the last day of the month, you can tell shutdown to reboot 24 hours from now.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks