Crontab is the command used to automate script execution on a regular basis

Commonly used parameters

  • crontab -lList all tasks that are automatically performed on a regular basis
  • crontab -eEdit all tasks that are automatically performed regularly

Task format

Run cycle script path log outputCopy the code

Such as:

 */5 * * * * /usr/local/agenttools/agent/check_tmp_agent.sh >/dev/null 2>&1
Copy the code

The lifecycle

 *    *    *    *    *
 -    -    -    -    -
 |    |    |    |    |
 |    |    |    |    +----- week (0 - 6) (sunday 0)
 |    |    |    +---------- month (1 - 12) 
 |    |    +--------------- day (1 - 31)
 |    +-------------------- hour (0 - 23)
 +------------------------- minute (0 - 59)
Copy the code

In addition to specific values, special characters may be used:

  • *: Take any possible value
  • .: Specifies the value of a list, for example,10,12,14,20
  • -: Specifies a range of values, for example,12-14
  • /: Specifies the value of the step, that is, the interval frequency, for example,30 * /If it is written inminuteField, indicating that the command is executed every 30 minutes

The script path

The absolute path of the script.

 /usr/local/agenttools/agent/check_tmp_agent.sh
Copy the code

Log output

 >/dev/null 2>&1
Copy the code
  • /dev/nullRepresents the device empty file
  • The standard inputstdinThe file descriptor of is0
  • The standard outputstdoutThe file descriptor of is1
  • The standard errorstderrThe file descriptor of is2

No Log output

 > /dev/null 2>&1
Copy the code

Standard Output log

 > /tmp/out.log
Copy the code

or

 1> /tmp/out.log
Copy the code

Standard error log

 2> /tmp/err.log
Copy the code

Standard output + standard error log

 > /tmp/total.log 2>&1
Copy the code

\