[CentOS] Confusion about scheduling tasks with crontab

Ron Loftin reloftin at twcny.rr.com
Sun Oct 18 15:46:39 UTC 2009


On Sun, 2009-10-18 at 11:28 -0400, Brett Serkez wrote:
> On Sun, Oct 18, 2009 at 11:11 AM, ne... <guhvies at gmail.com> wrote:
> > On Sun, Oct 18, 2009 at 16:09, Niki Kovacs <contact at kikinovak.net> wrote:
> >
> >> I have to setup a scheduled task on a server, and I just read through
> >> some crontab docs. Now I'm confused. It's not so much the syntax of the
> >> cron job to define (I got that), it's more... how do I get to define it?
> >> Use a text editor (vi or the likes) to edit /etc/crontab directly? Or
> >> create some empty file in /etc/cron.daily or /etc/cron.hourly or the
> >> likes and then edit it using crontab -e ?
> > As root, crontab -e. This is all you need.
> 
> If the script is to run as root and you aren't overly concerned about
> the precise time your script runs, only that it runs at these
> intervals, you can place your script or a soft-link to your script in
> one of the directories /etc/cron.monthly, /etc/cron.weekly,
> /etc/cron.daily and /etc/cron.hourly.
> 
> Any output from your script will be emailed to you, if this is setup.
> 
> To the best of my knowledge the scripts in these directories are run
> in alphabetical order, you can control the order if desired by the
> naming of the script.
> 
> In this case, crontab -e is not needed, create your script in our
> favorite editor.

Some more detail here:

You can use your "favorite editor" in conjunction with "crontab -e" just
by setting the EDITOR or VISUAL environment variable to specify the
editor to be used ( reference "man crontab" ).

Also, while creating links to your scripts in the /etc/cron.[hourly|
daily|weekly|monthly] is a valid approach, if you do very much of this
your system will become quite busy at 1 minute after each hour, and
shortly after 4AM, since that's when all that stuff runs.  For more
information, you should READ ( and NOT modify ) /etc/crontab,
and /usr/bin/run-parts ( the script that actually executes the stuff
in /etc/cron.[hourly|daily|weekly|monthly] for you.  The alternative
here is to edit root's crontab ( "crontab -e" as root ) to schedule jobs
to run at alternative times.

Cron and the associated commands such as "at" and "batch" are old-school
Unix commands.  They have a lot of functionality and a lot of
flexibility, but you have to dig into them and experiment with them to
learn enough to get the full benefits.

Since you're just starting in this area, experimenting with
non-production tasks and possibly environments is strongly encouraged.

> 
> Brett
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos
-- 
Ron Loftin                      reloftin at twcny.rr.com

"God, root, what is difference ?"       Piter from UserFriendly




More information about the CentOS mailing list