Bleah, missed some during the cut and paste...
>> If you want to adjust the master crontab it is /etc/crontab. If you wish
to adjust your personal crontab, just type:
>>
>> crontab -e
>
> Ummm...Thanks Logan & Kwan, but, I don't have a /etc/crontab, and crontab -e
produces a medium size list of zerors down the left column.
>
> As far as dropping scripts - I have no idea how that is done. or how a
script is executed. I seem to remember a GUI that would allow me to import
a script, set the date & time of execution and allow me to put it where I
wanted it.
Here's a short intro to using cron:
Cron is a system utility to automatically run commands at a certain time.
There are system and user crons in traditional Linux. Other systems such as
Solaris and Linux also have daily, monthly and hourly execution folders that
hide the cron commands themselves.
System and user crons are configured by editing the associated crontab file.
For the system this is usually in /etc/crontab but may exist in other
locations depending on the Unix system. User crontabs are often stored in
/var/spool/cron.
I'll start with user crons.
You can view the crontab associated with a user with the following command:
crontab -l
This displays the contents of the /var/spool/cron/USER file.
On Linux systems you'll note that there's a message in the file warning you
not to edit the file directly. This is a precaution because and incorrect cron
can lead to strange behaviour. Thus it's usually better to do this:
crontab -l > crontab.in
You can then edit the crontab.in with your favorite editor. Once you have
edited the crontab you can install it with:
crontab crontab.in
The crontab file will look similar to the following:
5 * * * * /home/kwan/bin/loggit
It will follow this format:
Minute Hour Day Month DayOfWeek Command
The first five fields specify the time that a command will run. As the manpage
for the crontab file shows, these values have the following ranges:
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
The Minute field ranges from to 59 and specifies the minute that a command
will run. For example
5 * * * * /home/joe/bin/loggit
specifies that the 'loggit' program will run at five minutes past the hour
every hour. If instead you want 'loggit' to run every five minutes you can
use:
*/5 * * * * /home/joe/bin/loggit
The other time fields work in a similar fashion. Here are some other examples:
* * * * /home/joe/bin/loggit
Run at midnight every day
30 2 * * * /home/joe/bin/loggit
Run at 2:30AM every night
30 2 1 * * /home/joe/bin/loggit
Run at 2:30AM on the first day of the month
30 2 * * 5 /home/joe/bin/loggit
Run at 2:30AM every Friday
You can also specify ranges within the crontab. Check the crontab(5) manpage
for all the intricacies.
The main difference between the system crontab and the user crontab is the
existence of a 'user' field. This allows system crons to run with the
effective ID of a different user, which is important for security.
Another thing to keep in mind when editing crontabs is that the PATH is not
set inside the cron. You'll thus need to either put the full path to commands
or explicitly set the PATH inside your crontab.
Things to beware:
Be very careful about permissions of scripts run through cron. Many will run
with root permissions to it's imperative that they're only writable by root or
similarly privileged users.
Because scripts run at usually odd times, thoroughly test your scripts before
committing them to cron. Once you have committed them the biggest source of
errors is usually incorrect permissions or missing PATH. Also, certain
programs may require a controlling terminal which may not exist depending on
the system.
-- * The Digital Hermit http://www.digitalhermit.com * Unix and Linux Solutions kwan@digitalhermit.com-- * The Digital Hermit http://www.digitalhermit.com * Unix and Linux Solutions kwan@digitalhermit.com ----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.
This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:59:16 EDT