I want to restart my server every week sunday
Hi all,
I want to set a crontab job for restarting my linux machine every sunday .. How to do this ? JayaraJMohan.J |
As root user:
Code:
crontab -e Code:
30 1 * * 7 /sbin/shutdown -r now |
man crontab: http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab
man 5 crontab: http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5 |
Quote:
|
Alright,
I'll assume, that you want to reboot the system whenever it reaches seven days uptime.. Keep on with me, and follow the instructions.. First, we will create a new script, shell script, run: Code:
nano /bin/RestartMe Code:
#!/bin/bash Code:
CTRL + X then Hit Y and then ENTER Code:
chmod 755 /bin/RestartMe To open crontab editor: Code:
crontab -e Code:
30 2 * * * /bin/RestartMe Summary: The crontab we sat above, will run the script every night at 2:30 AM server time, thus the script will check for the server uptime, if it's 7 days, a system reboot will be fired. The reboot command will wait 2 minutes before doing the real reboot, this way it gives a chance for any logged user to finish any running work. Otherwise, if you want to reboot the system on Sunday after 2 after midnigh (Monday Early Morning), no matter how long is the uptime.. go like: Code:
crontab -e Code:
30 2 * * 1 /bin/RestartMe Regards.. |
Great tut :)
Thanks guys easy and understandable.
|
Quote:
If OP wants server should be restarted on sunday then I think a simple cronjob with shutdown -r now or init 0 command will do the task. |
All times are GMT -5. The time now is 06:18 AM. |