Linux的定时任务主要依赖于crontab命令,crontab命令的功能是在一定的时间间隔调度一些命令的执行。在Linux中做定时任务时,仅需要在/etc/crontab 文件中增加自己需要设置的定时任务频次和需要执行的脚本内容即可。
先来查看/etc/crontab文件
cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed