LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cron (https://www.linuxquestions.org/questions/linux-general-1/cron-38883/)

sore 12-19-2002 12:28 PM

Cron
 
Can I make Cron to automaticly shutdown my computer? And if how do I do it? Must a user be loged in to run cron jobs?
I would like to just start the computer without logging in and then letting it automaticly shutdown later.

SlickWilly 12-19-2002 02:57 PM

> Can I make Cron to automaticly shutdown my computer?

Yes!

>And if how do I do it? Must a user be loged in to run cron jobs?

No, you don't have to be logged in. You can do it via the use of cron jobs. They're scripts / programs which can be scheduled to run at certain times (hourly, daily, weekly, once a year.. what have you).

To shudown your machine you can use :

shutdown -h now

or more recently

halt

halt will call shutdown anyway, but may be easier to remember. I like to use the shutdown command because you won't find halt on other unix's (and I started on AIX so it's ingrained)

To make this happen automatically :

crontab -e
- pulls up a blank editor for you to edit your cron jobs :

15 23 * * * /sbin/shutdown -h now
- tells cron to execute the shutdown at 11:15pm every day

:wq
- writes the file.

You're set.

When you run crontab -e you're writing the crontab for that user and so they are the user who will execute the commands. So, you'll need to be root, or someone who has the privs to /sbin/shutdown.

Shutdown has a couple of other flags instead of -h (halt). The other useful one -r does a reboot. And it can take a time as argument so, you might want to shutdown in 30 minutes you could

shutdown -h +30

see man shutdown, man halt, man cron for all of the above.

:)

Slick.

sore 12-20-2002 09:31 AM

Thanks alot for the answer! Works perfectly.


All times are GMT -5. The time now is 04:15 AM.