Linux Scheduled Tasks

Source: Internet
Author: User

There are three main tasks that can be achieved in Linux, namely At,batch,cron.* AT

The AT command is used to perform a one-time scheduled task, using/etc/at.allow (whitelist),/etc/at.deny (blacklist) control to allow those users to use the AT command, and only the root user can use if none of the two files exist.
Centos7 the/etc/at.deny file exists by default, and this file is empty, indicating that all users can use the at task.

使用格式:at  [option]  time     -m  at的工作完成后不管有没有输出,都用email通知使用者工作完成。    -l  类似于atq,列出at的任务列表    -d  类似于atrm,删除at任务    -c #    列出id为#的任务实际运行的工作指令TIME格式:    HH:MM           HH:MM   YYYY-MM-DD      HH:MM +* Unit[minutes、hour、day、weeks]  #在某个时间再加个时间例如 at  now  +5 minutes   五分钟后执行任务    at  now +5 minutes     echo "hello world" >/dev/pts/4      #输出到终端

Note: When all tasks are completed, the results are sent to the user, and the default mail address is/var/spool/mail/username

Use the MAIL/MAILX command to enter the appropriate number to view.

* Batch

Like at, it is a one-time task that does not need to be specified and automatically executes when the system is idle. Rarely used.
Usage:
Batch executes the carriage return, enters the interactive interface, presses CTRL+D to submit the task

* crontab

Crontab, used to provide recurring scheduled tasks
Related packages:
Cronie main package, providing Crond
The Cronie-anacron helper package, which is used to monitor whether Crond is performing correctly, for example, when the system shuts down when the task is executed, Crond cannot perform the task, and when the system boots and is anacron monitored for crond execution failure, perform the task immediately.
Crontabs provides maintenance tools

[[email protected] ~]# rpm -qa | grep croncronie-1.4.11-14.el7_2.1.x86_64crontabs-1.11-6.20121102git.el7.noarchcronie-anacron-1.4.11-14.el7_2.1.x86_64

Related documents:
/etc/cron.allow run the list of users who executed Crond
/etc/cron.deny List of users who refused to execute Crond
/etc/crontab System Task File
/etc/cron.d/System Tasks Folder
To schedule a task:
System cron tasks, typically used to perform system maintenance operations/etc/crontab/etc/cron.d/*
User cron tasks, typically used for user action tasks/var/spool/cron/user_name
Configuration file Format:

    系统任务 /etc/crontab         *  *  *  *  * user-name  command    用户任务 /var/spool/cron/user_name         *  *  *  *  *   command        #区别在于不用指定用户         

Time Representation method:
    1) specific time, a specific value
    2) , representing all values, Perform task
    3) discrete values every time, comma-separated "#,#"
    4) consecutive values, short minus sign separated by "#-#"
     5) Specify the step size on the specified range, "
/3" (run every 3 minutes), "20-50/3" (run every 20-50 minutes within 3 minutes)

示例建立系统任务:     [[email protected] cron.d]# vim /etc/crontab     * */3 * * *    gentoo  /bin/bash  wall <123.txt    0 */3 * * *    gentoo /bin/bash   wall <123.txt     第一个是错误示例,当大范围为*时,小范围要给具体值建立用户任务:root用户下为别的用户建立用户任务: (只有root能为别的用户建任务)    [[email protected] ~]# crontab -u gentoo普通用户自己建立用户任务:    [[email protected] ~]# crontab -e默认情况下,crond执行的所有命令输出都将以邮件方式发送给相应的用户,如果不想发到邮箱则需要使用重定向:command >/dev/null  正确的扔掉,错误的发送邮件command &>/dev/null 所有的都扔掉当用户要实现秒级别的任务或则不能被相应*的取值范围整除的数,则可以通过sleep命令实现.sleep   # (smhd)  s秒,m分,h时,d天例如实现每3秒执行一次ps命令:* * * * *  sleep 3s ; ps 例如每7分钟执行一次ps命令:(分钟的取值范围为1-60,不能被7整除,实际上最后一轮并没有执行)* * * * * sleep  7m ; ps

Linux Scheduled Tasks

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.