Scheduled task scheduling in 5-linux

crond task scheduling

crontab for timing task scheduling

overview

Task scheduling: refers to a specific command or program executed by the system at a certain time

Task scheduling classification:

  • System work: some important work must be performed repeatedly
  • Individual user work: hope to execute certain programs regularly

basic grammar

crontab [选项]

Common options

  • -e: Edit crontab scheduled tasks
  • -l: Query crontab tasks, list the task list
  • -r: Delete all crontab tasks of the current user

quick start

image.png

Explanation of special symbols

special symbols meaning
* means any time. For example, when the first placeholder is *, it means every minute of an hour
, Indicates discrete time. For example, the command: 0,8,12,16 * * *, means to execute the command once every day at 8:00, 12:00, and 16:00
- represents continuous time. For example, the command: 0 5 * * 1-6indicates that the command will be executed at 5:00 a.m. from Monday to Saturday
*/n How often the delegate is executed. For example, the command: */10 * * * *, means to execute the command every 10 minutes

Applications

  • Append the current date information to the /tmp/mydate file every minute
    • */1 * * * * date >> /tmp/mydate
  • Every minute, append the current date and calendar to the /home/mycal file
    • step
    • vim /home/my.shWrite content, date >> /home/mycal and cal >> /home/mycal
    • Add execution permission to my.sh,chmod u+x /home/my.sh
    • crontab -eAdd command:*/1 * * * * /home/my.sh

crond related commands

  • crontab -r: Terminate task scheduling
  • crontab -l: List the current task scheduling
  • service crond restart: restart task scheduling

at timed task

basic introduction

  • The at command is a one-time scheduled task. The daemon process of at will run in background mode and check the job queue to run.
  • By default, the atd daemon checks the job queue every 60s. When there is a job, it checks the job running time. If the time matches the current time, the job is run.
  • The at command is a one-time scheduled task . After a task is executed, it will no longer be executed.
  • When using the at command, you must ensure that the atd process is started, which can ps -ef | grep atdbe checked by the command.

at command format

at [选项] [时间]

When input is complete, enter ctrl + Dto indicate the end of the input command (enter twice)

When entering the at command, if you want to delete, you need to pressctrl+del

at command options

image.png

Definition of at time

  • I accept designation at time of the hh:mm type on the day. If the time has passed, it will be executed the next day.
  • Use vague words to specify time such as: midnight, noon, etc.
  • Use the 12-hour clock, and add am or pm after the time to indicate whether it is morning or afternoon. Example: 6pm
  • Specifies the specific date on which the command will be executed
    • mm/dd/yy 或 dd.mm.yy
    • The specified date must follow the specified time: 4:00 2021-03-1
  • Use relative timing
    • Specified format:now + 时间大小 时间单位
    • Time unit: minutes, hours, days, weeks
    • For example: now + 5 minutes means: execute the command after 5 minutes
  • Directly use today and tomorrow to specify the completion time

other instructions

  • atq: Display work tasks that are not executed in the system
  • atrm 编号: Delete the task that has been set

Guess you like

Origin blog.csdn.net/qq_45575167/article/details/131947795