Linux Command Summary --crontab command

 

1 Introduction

 

crontab file meaning :

crontab file created by the user, each row represents a task, each field representing each row of a setting, its format is divided into six fields, set the time period is the period of the first five, the sixth paragraph is command section to be executed in the following format:

Open the file (vi / etc / crontab) you will see the following:

The first four lines are used to configure the environment variables to run crond task

The first line SHELL variable specifies the system which shell to use, here is bash

The second line specifies the path to the PATH variable command system to perform

The third line MAILTO variable specifies the crond task execution information will be sent via e-mail to the root user

If the MAILTO variable is empty, it means not to send information to the user task execution

HOME variable fourth line specifies the home directory to use when executing commands or scripts.

An asterisk (*): On behalf of all possible values, such as the month field is an asterisk, it indicates that the command is executed operation after a month constraints to meet other fields.

Comma (,): a comma-separated values ​​can be used to specify a list of ranges, e.g., "1,2,5,7,8,9"

The bar (-): can represent an integer in the range of a bar between the integer, e.g., "2-6" indicates "2,3,4,5,6"

Forward slash (/): n frequency intervals can slash specified time, for example, "0-23 / 2" is performed once every two hours.

Summary:
    representation of the number 2 best to use Arabic numerals display
    week and day is best not to use
    a scheduled task to add annotations
    can be directed to a log file or empty file
    regular tasks must be an absolute path, and the directory must exist before the results
    crontab Service be sure to open the run

 

 

 2. Detailed

crontab: daemon regular tasks to the nearest minute, designs seconds we generally write the script -> Alarm equivalent to
        a log file: ll / var / log / cron *
        Edit the file: vim / etc / crontab        
        process: ps -ef | grep crond ==> /etc/init.d/crond restart
        role: regular backup, real-time backup

Common command parameters

1

2

3

4

5

6

7

8

usage:  crontab [-u user] file

        crontab [-u user] [ -e | -l | -r ]

                (default operation is replace, per 1003.2)

        -e   编辑,修改  (edit user's crontab)

        -l  查看定时任务 (list user's crontab)

        -r  删除      (delete user's crontab)

        -i  提示,确认  (prompt before deleting user's crontab)

        -u  指定用户    (user)

 

Cron job classification


Task scheduling of Linux into two categories, task scheduling system and user tasks scheduling.
    Task scheduling system: the system work to be performed periodically, such as writing data to the hard disk cache, log clean-up. 
        In the / etc / crontab file, this is the task scheduling system configuration files.
    User task scheduling: Users work to be performed on a regular basis, such as user data backup, regular e-mail reminders.
        Users can use the tools to customize their own crontab scheduled tasks.
        In crontab files are stored in / var / spool / cron directory. Consistent with its file name and user name

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

1.系统定时任务:例如清理系统日志,清理系统缓存   -->不过多的关注

    查询系统定时处理任务的路径:

        路径1:

            cd /etc/logrotate.d/        -->可以写定时任务

            less syslog

        路径2:

            cat /etc/crontab   -->不推荐使用,但是可以看格式

        路径3:

             ls /etc/ | grep cron*

                 anacrontab

                 cron.d                 -->同路径2 ,可以写定时任务 

                 cron.daily

                 cron.deny              -->控制普通用户使用定时任务crontab

                 cron.hourly

                 cron.monthly

                 crontab

                 cron.weekly

2.用户的定时任务      -->关注重点

Guess you like

Origin www.cnblogs.com/hanjiali/p/11580660.html