PDA

View Full Version : [ubuntu] daily cron job for reboot?



thepiston
June 12th, 2008, 05:44 PM
I'd like to reboot my server every night at 3am. I've never written a cron or know how to go about it - can anyone show me where to go?

Titan8990
June 12th, 2008, 05:46 PM
Here is the forum's crontab tutorial: http://ubuntuforums.org/showthread.php?t=102626&highlight=cron

HalPomeranz
June 12th, 2008, 05:46 PM
https://help.ubuntu.com/community/CronHowto

Btw, you shouldn't really need to reboot your machine every night. Why do you feel this is necessary? Maybe there's something wrong with your setup that should be corrected...

Titan8990
June 12th, 2008, 06:00 PM
I agree, all my machines run 24/7.

thepiston
June 12th, 2008, 06:02 PM
there's a nuance in our software that causes comboboxes to stall unless it's rebooted - i'm just doing this as a patch until we fix the problem.

One problem - everytime I input "sudo reboot" it asks me for my password. Do I need to do anything about that or can I just add this:


00 03 * * * sudo reboot

Titan8990
June 12th, 2008, 06:04 PM
That will not work. You will need to make the cron job as root to do commands that require root access. You can't "sudo" in scripts.

thepiston
June 12th, 2008, 06:09 PM
That will not work. You will need to make the cron job as root to do commands that require root access. You can't "sudo" in scripts.
I was root when I created the cron, is that what you mean?

ukripper
June 12th, 2008, 06:14 PM
you can create bash script and add
00 03 * * * reboot to it and place that bash script to /etc/rc.local so you don't have to put any password.

alternatively, go for editing sudoers route.

HalPomeranz
June 12th, 2008, 06:16 PM
I was root when I created the cron, is that what you mean?

That's what they meant. If you're adding the reboot command to root's crontab, you don't need the "sudo" statement because the command will be run with root privileges by cron.

thepiston
June 12th, 2008, 06:19 PM
ok, gotcha - i'll remove it