Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron basics

Status
Not open for further replies.

Hondy

Technical User
Mar 3, 2003
864
GB
Hi

I need to run a script once a day at 10am
How do I actually edit the crontab and save it, and what do I need to put in the crontab. I'm using CentOS.

Also do you have to be logged in as the user that created the job for it to run?

Thanks
 
crontab -e will bring up your favorite editor. Afterwards you will need to put the following line :
0 10 * * * /your/script_name

You do not need to be logged in to have cron run. Cron will run the script as the user you were logged in as when you typed crontab -e. Below is more info about cron. Again, I highly recommend reading man cron.

Each line of CRONTAB has the following structure:
<Minute> <Hour> <Day> <Month> <Day of Week> <Command line>
Position: Values:
Minute 0-59
Hour 0-23
Day 1-31
Month 1-12
Day of week 0-6 (0=Sunday, 1=Monday, ..., 6=Saturday)
 
ok but if I do crontab -e, it gives me a terminal style window, i have read :qw quits but I can't get it to work.

Then I read that you can go into /var/spool/cron/user and edit it directly with something like gedit.

When I do a crontab -l it shows my job in there like:

59 17 * * * /admin/backup/backup.sh

Assuming that is correct it didn't run at 17:59 as expected, I restarted the crond service beforehand to make sure, but what is going on?

I've had a look at man cron but I'm no better off, it seems its correct but the script doesn't run...

Any ideas?
 
I know the Di hard Gurus will frown upon this but I find Webmin makes configuring this type of task very simple
(ducks for cover)
 
The vi command is ":wq", not ":qw".

The crontab entry looks ok. Is the script executable? Can you run it manually? Does it depend on any environment variables (path, etc)?
 
ah I got it working, it turns out it was my error.

Is there anything I have to run if the server is rebooted or will it retain it?

Thanks for the suggestion IPGuru


 
As long as crond is automatically started, there's nothing else needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top