LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 11-03-2011, 10:09 PM   #1
Squerl101
Member
 
Registered: Nov 2011
Location: Muskego, WI
Posts: 34

Rep: Reputation: 0
How do i run a command every day at a certain time automatically?


Hey guys.

I am a noob. I just want to know how to make a command automatically run EVERY DAY at a certain time. I want it to run /sbin/shutdown -h 22:00. This needs to run everyday at 10:00PM. Can someone tell me how i can make it do it automatically? Thanks.
 
Old 11-03-2011, 10:16 PM   #2
jefro
Guru
 
Registered: Mar 2008
Posts: 12,093

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
Hello.

I think most systems support a thing called cron. Cron can get a bit tricky but if you remember cron is sort of like a user with it's own rights and authentication then you are OK. You want to run that script before to be sure it runs.
 
0 members found this post helpful.
Old 11-03-2011, 10:20 PM   #3
Squerl101
Member
 
Registered: Nov 2011
Location: Muskego, WI
Posts: 34

Original Poster
Rep: Reputation: 0
Thanks, but what do i have to enter into the terminal to have it shutdown everyday at 10:00?
 
Old 11-03-2011, 10:56 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,247

Rep: Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558
As root, or after sudo, edit /etc/crontab.

Enter this line at the end:
Code:
0 22 * * * root shutdown -h now
Make sure you have an empty line as last line!

If you are a GUI only person, you can edit a file as root by pressing CTL-F2 and tell that you want to run an application as root, and then choose you fav editor

jlinkels
 
1 members found this post helpful.
Old 11-04-2011, 06:14 AM   #5
sswuste
LQ Newbie
 
Registered: Nov 2011
Posts: 10

Rep: Reputation: Disabled
You might want to specify the complete path to the shutdown command in your cronjob: /sbin/shutdown
 
Old 11-04-2011, 06:21 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 189Reputation: 189
Quote:
Originally Posted by jefro View Post
Hello.

I think most systems support a thing called cron. Cron can get a bit tricky but if you remember cron is sort of like a user with it's own rights and authentication then you are OK. You want to run that script before to be sure it runs.
Its my understanding, that if you run
Code:
crontab -e
as any user, then it creates a crontab for that user, and anything runs as that user.. At least, that is how it appears to be for my FC15 box. Am I correct in my understanding?

Note: for a shutdown command, it would need to be done as root, as stated in other replies. Unless passwordless shutdown has been enabled in sudoers.
 
1 members found this post helpful.
Old 11-04-2011, 06:39 AM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,247

Rep: Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558
Quote:
Originally Posted by fukawi1 View Post
Its my understanding, that if you run
Code:
crontab -e
as any user, then it creates a crontab for that user, and anything runs as that user.. At least, that is how it appears to be for my FC15 box. Am I correct in my understanding?
That is correct, but this command opens the default editor which is in most cases vi, and that could be surprising for users who don't how to use or get out of vi. crontab -e is the recommended and only correct way to edit a personal crontab from the command line though.

The shutdown command has to be run as root, and it really fits better in the system-wide /etc/crontab. If you are right and shutdown can be run by a member of the sudoers group a personal crontab might work, but it makes the system less transparent. You don't want to go through a dozen crontabs to see who is responsible for shutting down the machine.

jlinkels
 
1 members found this post helpful.
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To run a shell script automatically on time A.Hariharasudhan Linux - Server 1 10-08-2010 02:20 AM
How to run a shell script evey day automatically at a particular time krevathi1912 Programming 3 09-22-2007 02:15 PM
run program automatically at specific time simon_qwl Programming 2 03-20-2005 11:58 AM
How to start scriptfile(tomcat) automatically at boot-time run fmohideen76 Linux - General 4 07-11-2002 11:44 PM


All times are GMT -5. The time now is 05:37 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration