Difference between revisions of "Cron and at Commnads"

From rbachwiki
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:Atdcommand.jpg|thumb|at command]]
==Scheduling Commands with ATD==
at 10:15pm
'''After being invoked, the at command displays an at> prompt allowing you to type com- mands to be executed, one per line. After the commands have been entered, use the Crtl+d key combination to schedule the commands using atd.'''
[root@server1 ~]# at 10:15pm July 15
at> date > /root/atfile
at> who >> /root/atfile
at> Ctrl+d
job 1 at Wed Jul 15 22:15:00 2015
'''Other Commands'''
at -cl
at -d 1 #remove job 1
at -f # used to run an external script file
==Cron Jobs==
==Cron Jobs==
[[File:Chron.jpg|thumb|Cron Command]]
'''A cron table includes six fields separated by space or tab characters. The first five fields specify the times to run the command, and the sixth field is the absolute pathname to the command to be executed.''' <br>
As with the at command, you can place commands in a shell script and schedule the shell script to run repetitively; in this case, the sixth field is the absolute pathname to the shell script. <br>
Each of the fields in a cron table is depicted in Figure 9-5. Thus, to execute the /root/myscript shell script at 5:20 PM and 5:40 PM Monday to Friday regardless of the day of the month or month of the year, you could use the cron table depicted in Figure 9-6. <br>
The first field in Figure 9-6 specifies the minute past the hour. Because the command must be run at 20 minutes and 40 minutes past the hour, this field has two values, sepa- rated by a comma. <br>
The second field specifies the time in 24-hour format, with 5 PM being the 17th hour. <br>
The third and fourth fields specify the day of month and month of year, respectively, to run the command. <br>
Because the command might run during any month regardless of the day of month, both fields use the * wildcard shell metacharacter to match all values. <br>
The final field indicates the day of the week to run the command; as with the first field, the command must be run on multiple days, but a range of days was specified (day 1 to day 5).<br>


A cron table includes six fields separated by space or tab characters. The first five fields spec- ify the times to run the command, and the sixth field is the absolute pathname to the com- mand to be executed. As with the at command, you can place commands in a shell script and schedule the shell script to run repetitively; in this case, the sixth field is the absolute pathname to the shell script. Each of the fields in a cron table is depicted in Figure 9-5. Thus, to execute the /root/myscript shell script at 5:20 PM and 5:40 PM Monday to Friday regardless of the day of the month or month of the year, you could use the cron table depicted in Figure 9-6. The first field in Figure 9-6 specifies the minute past the hour. Because the command must be run at 20 minutes and 40 minutes past the hour, this field has two values, sepa- rated by a comma. The second field specifies the time in 24-hour format, with 5 PM being the 17th hour. The third and fourth fields specify the day of month and month of year, respectively, to run the command. Because the command might run during any month regardless of the day of month, both fields use the * wildcard shell metacharacter to match all values. The final field indicates the day of the week to run the command; as with the first field, the command must be run on multiple days, but a range of days was specified (day 1 to day 5).
Two different types of cron tables are used by the cron daemon: user cron tables and system cron tables. User cron tables represent tasks that individual users schedule and exist in the /var/spool/cron directory on Fedora systems and the /var/spool/cron/crontabs directory on Ubuntu systems. System cron tables contain system tasks and exist in the /etc/crontab file as well as the /etc/cron.d directory.
Two different types of cron tables are used by the cron daemon: user cron tables and system cron tables. User cron tables represent tasks that individual users schedule and exist in the /var/spool/cron directory on Fedora systems and the /var/spool/cron/crontabs directory on Ubuntu systems. System cron tables contain system tasks and exist in the /etc/crontab file as well as the /etc/cron.d directory.
 
crontab -e # creates a crontab file for the current user
[[File:Chron.jpg|thumb|Cron Command]]
crontab -l # list user crontab file
crontab -r # removes a crontab table
===System Cron Tables===
/etc/crontab
== Crontab Example ==
[https://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/ crontab examples]

Latest revision as of 15:09, 17 May 2019

at command

Scheduling Commands with ATD

at 10:15pm 

After being invoked, the at command displays an at> prompt allowing you to type com- mands to be executed, one per line. After the commands have been entered, use the Crtl+d key combination to schedule the commands using atd.

[root@server1 ~]# at 10:15pm July 15 
at> date > /root/atfile 
at> who >> /root/atfile 
at> Ctrl+d
job 1 at Wed Jul 15 22:15:00 2015

Other Commands

at -cl
at -d 1 #remove job 1
at -f # used to run an external script file

Cron Jobs

Cron Command

A cron table includes six fields separated by space or tab characters. The first five fields specify the times to run the command, and the sixth field is the absolute pathname to the command to be executed.

As with the at command, you can place commands in a shell script and schedule the shell script to run repetitively; in this case, the sixth field is the absolute pathname to the shell script.
Each of the fields in a cron table is depicted in Figure 9-5. Thus, to execute the /root/myscript shell script at 5:20 PM and 5:40 PM Monday to Friday regardless of the day of the month or month of the year, you could use the cron table depicted in Figure 9-6.
The first field in Figure 9-6 specifies the minute past the hour. Because the command must be run at 20 minutes and 40 minutes past the hour, this field has two values, sepa- rated by a comma.
The second field specifies the time in 24-hour format, with 5 PM being the 17th hour.
The third and fourth fields specify the day of month and month of year, respectively, to run the command.
Because the command might run during any month regardless of the day of month, both fields use the * wildcard shell metacharacter to match all values.
The final field indicates the day of the week to run the command; as with the first field, the command must be run on multiple days, but a range of days was specified (day 1 to day 5).

Two different types of cron tables are used by the cron daemon: user cron tables and system cron tables. User cron tables represent tasks that individual users schedule and exist in the /var/spool/cron directory on Fedora systems and the /var/spool/cron/crontabs directory on Ubuntu systems. System cron tables contain system tasks and exist in the /etc/crontab file as well as the /etc/cron.d directory.

crontab -e # creates a crontab file for the current user
crontab -l # list user crontab file
crontab -r # removes a crontab table

System Cron Tables

/etc/crontab

Crontab Example

crontab examples