LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-19-2002, 12:28 PM   #1
sore
LQ Newbie
 
Registered: Dec 2002
Location: Sweden
Distribution: suse 8.2
Posts: 22

Rep: Reputation: 15
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.
 
Old 12-19-2002, 02:57 PM   #2
SlickWilly
Member
 
Registered: Dec 2002
Posts: 327

Rep: Reputation: 30
> 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.
 
Old 12-20-2002, 09:31 AM   #3
sore
LQ Newbie
 
Registered: Dec 2002
Location: Sweden
Distribution: suse 8.2
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks alot for the answer! Works perfectly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
cron.allow and cron.deny in slackware? tl64 Slackware 5 10-13-2005 09:44 PM
No More Cron Mail, Cron Error? Xhost Linux - General 3 07-26-2004 04:28 PM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration