Hi,
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 ?
Anyway, here's what I'd like to do.
I have a script:
/root/scripts/backup.sh
I want to run that script every day at 07:00 in the morning. Once. Now how would I go about that? The thing is: I'd like to know an orthodox way to go about this.
You can be laconic in your answers, I'll retrive the details in the docs.
Cheers,
Niki
On Sun, Oct 18, 2009 at 16:09, Niki Kovacs contact@kikinovak.net wrote:
Hi,
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.
ne...
ne... a écrit :
On Sun, Oct 18, 2009 at 16:09, Niki Kovacs contact@kikinovak.net wrote:
Hi,
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.
ne...
Two minutes to respond. Wow, that was fast !
Thanks !
On Sun, Oct 18, 2009 at 11:11 AM, ne... guhvies@gmail.com wrote:
On Sun, Oct 18, 2009 at 16:09, Niki Kovacs contact@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.
Brett
On Sun, 2009-10-18 at 11:28 -0400, Brett Serkez wrote:
On Sun, Oct 18, 2009 at 11:11 AM, ne... guhvies@gmail.com wrote:
On Sun, Oct 18, 2009 at 16:09, Niki Kovacs contact@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@centos.org http://lists.centos.org/mailman/listinfo/centos
On 10/18/2009 11:13 AM Alan McKay wrote:
how would I go about that? The thing is: I'd like to know an orthodox way to go about this.
crontab -e
and then just put in your entry
- 7 * * * /your/command
I think you meant:
0 7 * * * /your/command
The asterisk will make the command run every minute during the seven o'clock hour. The OP wanted his script to run at 7:00
Yes?
On Sun, Oct 18, 2009 at 6:15 PM, ken gebser@mousecar.com wrote:
- 7 * * * /your/command
I think you meant:
0 7 * * * /your/command
The asterisk will make the command run every minute during the seven o'clock hour. The OP wanted his script to run at 7:00
Hee, hee, yeah, good catch :-) If I were doing it for me I'd have read the fine manual first :-)
At Sun, 18 Oct 2009 18:15:06 -0400 CentOS mailing list centos@centos.org wrote:
On 10/18/2009 11:13 AM Alan McKay wrote:
how would I go about that? The thing is: I'd like to know an orthodox way to go about this.
crontab -e
and then just put in your entry
- 7 * * * /your/command
I think you meant:
0 7 * * * /your/command
The asterisk will make the command run every minute during the seven o'clock hour. The OP wanted his script to run at 7:00
Yes?
No. The first field is the minutes (0), the second field is hours (7), then comes 'day of month' (*), month (*), 'day of week' (*). The script will run at 7:00AM, every day of every month on every day of the week (well the last is redundent...).
man 5 crontab
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos