This is the 22nd day of my participation in the Genwen Challenge

at

Specifies that certain commands will be executed at some point in the future, through the ATD daemon

systemctl status atd

At [选 词] TIME

At-l/ATQ # List all jobs AT-D/ATRM Task No. # Delete job AT-q # Specify queue to store (default is QUEUE A). Queue number is A-z A-Z, a total of 52, the larger the letter, the lower the priority.Copy the code

Mode of execution:

  • interactive

Type “AT time” at the shell prompt, then press Enter. On the next line, the shell waits for the user to continue typing the command to execute. Enter one command for each line. Press Ctrl+ D to finish entering all commands.

  • The specified file

Write each command into the shell script, and then run the commands in the shell script at the specified time using the following format: at time -f script file.

The result will be notified by email to /var/spool/mail/xxx

Time format
  • Time date HH :mm MM/DD/YY

23:59 03/15/2017

  • Hh :mm midnight tomorrow am…

17:20 tomorrow

  • Relative chronograph time point + number + time unit

now + 2 minutes 5pm + 3 days

cron

The process scheduling generated by the AT command is not periodic and can be executed only once when the time condition is met. But many times you need to execute a program periodically and repeatedly. Crontab is used to allow users to execute programs at fixed times or at fixed intervals.

Format:

Crontab [-u user] file

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

Only the root user can specify others’ schedules

The main parameters

  • E: Execute the text editor to set the schedule, and the built-in text editor is VI
  • R: Delete the current schedule table
  • L: List the current schedule

Compared with the AT command, the crontab command is suitable for completing tasks with fixed periods

The principle of

  1. The cron command is automatically launched at system startup by a shell script into the background, crond daemon.
  2. After cron starts, search the /var/spool/cron directory for crontab files named with the user name in /etc/passwd. The crontab files found will be loaded into memory.
  3. If no crontab file exists, the system goes to sleep to release system resources.
  4. Cron wakes up every minute to see if there are any commands that need to be run.
  5. If a user is found to have set the crontab file, it will run the commands specified in the file as that user. After the command is executed, any output is sent as an email to the owner of crontab or to the user specified in the MAILTO environment variable in the /etc/crontab file.

For users, they only need to write their crontab files and do not need to interfere with the crond process execution. Because a user has only one crontab file, the crontab file cannot be created or modified directly. You must run the crontab command to obtain the crontab file. The crontab command is used to install, delete, or list the crontab files used to drive the cron daemon.