Crontab command usage in Linux

Source: Internet
Author: User

Crond resident command for Task Scheduling
Crond is a Linux Command Used to regularly execute programs. After the operating system is installed, the task scheduling command is started by default. The crond command periodically checks whether there is any job to be executed every minute. If there is any job to be executed, the job is automatically executed. Linux task scheduling mainly includes the following two types:
1. work performed by the system: work to be performed periodically by the system, such as backing up system data and clearing Cache
2. Personal Work: The work that a user regularly performs, such as checking whether there are new emails on the email server every 10 minutes. This work can be set by each user.

Crontab is a scheduled task trigger in Unix systems. Its user permissions are recorded in the following two files:

File
Description
 
/Etc/cron. deny
Users listed in this file cannot use the crontab command.
 
/Etc/cron. allow
Users listed in this file can use the crontab command
 
/Var/spool/cron/
Is the crontab file of all users
 
/Var/spool/cron/crontabs
/Var/spool/cron/crontabs
 

The crontab command is in the format of crontab-L |-r |-E |-I [username]. The parameter meanings are shown in table 1:

Parameter Name
Description
Example
 
-L
Displays the contents of your crontab file.
Crontabl-l
 
-I
Prompt before deleting the crontab file
Crontabl-ri
 
-R
Delete a user's crontab file from the crontab directory
Crontabl-R
 
-E
Edit the user's crontab file
Crontabl-e
 

The crontab file created by the user is saved in/var/spool/cron, and its file name is consistent with the user name.
The format is divided into six segments. The first five segments are time sets, and the sixth segment is the command segment to be executed,
The format is as follows :*****
The meanings of the time period are shown in table 2:

Segment
Description
Value Range
 
Section 1
Minutes
0-59
 
Section 2
Represents the hour
0-23
 
Section 3
Represents a date
1-31
 
Fourth paragraph
Month
1-12
 
Section 5
The day of the week. 0 indicates Sunday.
0-6
 

For example, if the content of your crontab file is 29 19 *** echo its dinner time, the system displays 'its dinner time' at every day'
Example (create A cron process, and input the current time in test.txt every minute ):

1. log on to Linux as a common user (I use centos4.1)

2. $ crontab-e
Note: The default editor of the system is vim. If not, add the following shell:
$ Editor = vi
$ Export Editor

3. Enter "*/1 ***** date> $ home/test.txt", save and exit Vim

4. $ su Root

5. $ CD/etc/init. d

6 ../crond restart

Let's take a look at several specific examples:
● 0 */2 ***/sbin/service httpd restart indicates that Apache is restarted every two hours.

● 50 7 ***/sbin/service sshd start means to enable the SSH service at every day

● 50 22 ***/sbin/service sshd stop means to close the SSH service at every day

● 0 0 ** fsck/home check/home disk on the 1st and 15th of each month

● 1 ***/home/Bruce/backup: Execute the file/home/Bruce/backup at the first point of every hour.

● 00 03 ** 1-5 find/home "*. XXX "-mtime + 4-exec RM {}\; every Monday to Friday three o'clock, in the directory/home, find the file name *. xxx file, and delete the file four days ago.
● 30 6 */10 ** ls indicates that the LS command is executed at on the first, 11th, 21st, and 31st of each month.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.