Web Hosting Talk







View Full Version : What is a Cron Job?


.::DefCon::.
02-17-2002, 11:58 AM
Customers keep on asking me this (we are reselling Cobalt space) and I have no idea of what it is!

Has it got anything to do with the control panel? 'cause people always ask me: Can I do cron jobs and do you have a demo of your control panel?

So maybe these two things have something to do with each other?

Thanks guys,

Thomas

Daytripper
02-17-2002, 12:04 PM
"What is a cronjob, and how do I use it?
The cron daemon is a long running process that executes commands at specific dates and times. To schedule one-time only tasks with cron, use at or batch. For commands that need to be executed repeatedly (e.g. hourly, daily or weekly), use crontab, which has the following options: crontab filename Install filename as your crontab file.
crontab -e Edit your crontab file.
crontab -l Show your crontab file.
crontab -r Remove your crontab file.
MAILTO=user@domain.com Emails the output to the specified address.

The crontab command creates a crontab file containing commands and how often cron should execute them. Each entry in a crontab file consists of six fields, specified in the following order:

minute(s) hour(s) day(s) month(s) weekday(s) command(s)
The fields are separated by spaces or tabs. The first five are integer patterns and the sixth is the command to be executed. The following table briefly describes each of the fields.

Field Value Description
minute 0-59 The exact minute that the command sequence executes.
hour 0-23 The hour of the day that the command sequence executes.
day 1-31 The day of the month that the command sequence executes.
month 1-12 The month of the year that the command sequence executes.
weekday 0-6 The day of the week that the command sequence executes. Sunday=0, Monday = 1, Tuesday = 2, and so forth.
command Special The complete command sequence variable that is to be executed.

Each of the patterns from the first five fields may either be an asterisk (*) (meaning all legal values) or a list of elements separated by commas. An element is either a number or two numbers separated by a minus sign (meaning an inclusive range). Note that the specification of days may be made by two fields (day of the month and day of the week). If both are specified as a list of elements, both are followed. For example:

MAILTO=user@domain.com
0 0 1,15 * 1 /big/dom/xdomain/cgi-bin/scriptname.cgi
The cron daemon would run the program scriptname.cgi in the cgi-bin directory on the first and fifteenth of each month, as well as on every Monday. To specify days by only one field, the other field should be set to *. For example:

MAILTO=user@domain.com
0 0 * * 1 /big/dom/xdomain/cgi-bin/scriptname.cgi
The program would then only run on Mondays.

If a cron job specified in your crontab entry produces any error messages when it runs, they will be reported to you via email.

You may create crontab files in notepad (being sure to upload them in ASCII) or you may create them within telnet by simply typing:

mcedit cronfile.txt
For more information, consult the man pages. man pages are the directions and tutorials available to you right at the command line from within telnet. Type any of the following lines to open the relevant tutorials:

man 5 crontab {enter}
man 1 crontab {enter}
man cron {enter}
man at {enter}
man batch {enter}
man 1 cron {enter}
Note:
Your crontab file must end with a line feed - in other words, make sure to press [Enter] after the last line in the file. "

That should get you started

Softerweb
02-17-2002, 12:24 PM
In many ways cron is similar to Windows "scheduled tasks".

Common tasks to run through cron are logrotate, backup scripts, account setup scripts etc...

.::DefCon::.
02-17-2002, 01:25 PM
And how can I find out if a server supports it?
I use Cobalt RaQ4i. Does this type of server support cron jobs?

Thanks,

T.

Softerweb
02-17-2002, 02:40 PM
Sure, it is available. However, you will probably want to set it up for your customers on a per case basis.

Cobalt say they have disabled user access to crontab...here is the article of reference:
http://cobalt-knowledge.sun.com/cgi-bin/kbase.cfg/php/enduser/std_adp.php?p_sid=4-irv*7g&p_lva=&p_refno=010608-002721&p_created=992013163&p_sp=cF9ncmlkc29ydD0mcF9yb3dfY250PTQmcF9zZWFyY2hfdGV4dD1jcm9udGFiJnBfc2VhcmNoX3R5cGU9MyZwX3Byb2RfbHZsMT1_YW55fiZwX3Byb2RfbHZsMj1_YW55fiZwX2NhdF9sdmwxP X5hbnl_JnBfY2F0X2x2bDI9fmFueX4mcF9zb3J0X2J5PWRmbHQmcF9wYWdlPTE*&p_li=

Sorry for the long url...hope it works.

Anyway, if you have to give your users direct access to crontab I guess you would also have to give them telnet or ssh access, and also enable crontab, as described in the article above.

The easiest way to setup a scheduled task is to use cron.*, ie cron.daily, cron.hourly etc. The files placed in these folders are executed once per day, hour etc...