Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Jun 24, 2008 7:52 am 
Offline
Senior Newbie

Joined: Sat Jun 21, 2008 5:17 pm
Posts: 6
Website: http://myspace.com/djmicron
Hello,
i need to setup a scheduled task to automatically run the following command every hour:

Code:
perl '/myscripts/script.pl'


Any help is very appreciated

Thanks

Sal


Top
   
 Post subject:
PostPosted: Tue Jun 24, 2008 8:09 am 
Offline
Senior Newbie

Joined: Fri May 30, 2008 11:19 am
Posts: 11
You would want to use cron to accomplish this.

As the user that you want to run the command as you would run:

crontab -e

This will bring up an editor. Put the following in the editor and save it.

0 * * * * perl '/myscripts/script.pl'

This will run the command ever hour at 0 minutes of that hour.

--Sean


Top
   
 Post subject:
PostPosted: Tue Jun 24, 2008 9:04 am 
Offline
Senior Newbie

Joined: Sat Jun 21, 2008 5:17 pm
Posts: 6
Website: http://myspace.com/djmicron
Thank You very much.

Sal


Top
   
 Post subject:
PostPosted: Tue Jun 24, 2008 2:03 pm 
Offline
Senior Newbie

Joined: Sat Jun 21, 2008 5:17 pm
Posts: 6
Website: http://myspace.com/djmicron
Hello,
even if the task has been added to the edited crontab file, it is not running.

I have verified that the command i have added is correct by running it in terminal and it works, but i don't know what i can do to let the cron run by itself.

I see that when i run the crontab -e command it opens a file named "crontab" which contains the command i have added before, but i'm not sure if it has been saved in the right location, because if i open the file /etc/crontab it does not contain the command i have added.

Thank You

Sal


Top
   
 Post subject:
PostPosted: Tue Jun 24, 2008 2:10 pm 
Offline
Senior Member

Joined: Sun Nov 30, 2003 2:28 pm
Posts: 245
Sal,. /etc/crontab is the system level file, and you wouldn't expect to see your changes there. User crontabs are in /var/spool/cron/crontabs, but you won't be able to read that as a user, just as root, and you definitely don't want to edit them directly.

Try 'crontab -l' to list your user cron file. Using 'crontab -e' should create copy of what is in /var/spool/cron/crontab, and, when you save, put it back in place. You should see a message in the console "crontab: installing new crontab", and, if you look in /var/log/cron.log, a sequence like this:
Code:
Jun 24 13:06:28 speedy crontab[11270]: (steveg) BEGIN EDIT (steveg)
Jun 24 13:06:35 speedy crontab[11270]: (steveg) REPLACE (steveg)
Jun 24 13:06:35 speedy crontab[11270]: (steveg) END EDIT (steveg)
Jun 24 13:07:01 speedy /usr/sbin/cron[2833]: (steveg) RELOAD (crontabs/steveg)

If there's a problem, you should see an error message.

_________________
The irony is that Bill Gates claims to be making a stable operating system and Linus Torvalds claims to be trying to take over the world.
-- seen on the net


Top
   
 Post subject:
PostPosted: Tue Jun 24, 2008 3:38 pm 
Offline
Senior Newbie

Joined: Sat Jun 21, 2008 5:17 pm
Posts: 6
Website: http://myspace.com/djmicron
thank You Steve,
i have done 'crontab -l' and verified that cron job has been added to that file, but i don't see the cron.log inside the /var/log/ , so i think there is something wrong with cron on my ubuntu installation.

Is there some command i can run to force cron to start?


Thank You

Sal


Top
   
 Post subject:
PostPosted: Tue Jun 24, 2008 4:43 pm 
Offline
Senior Newbie

Joined: Sat Jun 21, 2008 5:17 pm
Posts: 6
Website: http://myspace.com/djmicron
i have done a research and it seems that it's not possible to run cron tasks as root user and it is what i tried to do, so i have added the task as normal user and it worked out.

Thank You

Sal


Top
   
 Post subject:
PostPosted: Tue Jun 24, 2008 5:09 pm 
Offline
Senior Member

Joined: Sun Nov 30, 2003 2:28 pm
Posts: 245
If you ever do need to add a root cronjob (or any other system account cron job), don't mess with /etc/crontab. Either add the script to one of /etc/cron.{daily,weekly,monthly), where it will run as root, or add a crontab fragment to /etc/cron.d. These fragments include a username between the time-spec and the actual command. See crontab(5) for details.

_________________
The irony is that Bill Gates claims to be making a stable operating system and Linus Torvalds claims to be trying to take over the world.

-- seen on the net


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group