[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cron Script

Posted on 2012-09-13
11
Medium Priority
?
523 Views
Last Modified: 2013-11-13
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.
0
Comment
Question by:SrikantRajeev
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 38393929
with cron, it may be simpler to schedule the job to run at the beginning of every month at 00:00 hrs.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38394375
crontab entry for 1st day of month:

0 0 1 * * /sbin/shutdown -r now
0
 
LVL 6

Expert Comment

by:g3nu1n3
ID: 38395901
0 0 * * * if [[ $(date +'%d') -eq $(cal | awk '!/^$/{ print $NF }' | tail -1) ]]; then /sbin/reboot; fi;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 85

Expert Comment

by:ozo
ID: 38397495
http:#a38395901 seems to restart 24 hours earlier than requested
0
 
LVL 1

Author Comment

by:SrikantRajeev
ID: 38397911
so which is the right syntax i need to use
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38398038
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? :)
0
 
LVL 85

Expert Comment

by:ozo
ID: 38398203
24:00 hrs on the last day of the month is the same as 00:00 hours on the first day of the month
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38398206
@ozo - that's what I mean ;)
0
 
LVL 85

Expert Comment

by:ozo
ID: 38398212
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.
0
 
LVL 6

Accepted Solution

by:
g3nu1n3 earned 1500 total points
ID: 38399012
Apologies, I based my answer on what I saw the first two experts provide. After reading over your question again, here is my suggestion and you can decide:

If you want the cron to run on the last day of the month at essentially the end of the day in terms of time:
59 23 * * * if [[ $(date +'%d') -eq $(cal | awk '!/^$/{ print $NF }' | tail -1) ]]; then /sbin/reboot; fi;

The command if [[ $(date +'%d') -eq $(cal | awk '!/^$/{ print $NF }' | tail -1) ]]; then /sbin/reboot; fi; will execute at 11:59pm on every day of every month. (This is what I suggest you use based on what you said, "restart my linux server at the end of every month at around 24:00 hrs.")
0
 
LVL 1

Author Closing Comment

by:SrikantRajeev
ID: 38493476
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question