crontab简介
通过crontab命令,可以在固定的间隔时间执行指定的系统指令或者shell脚本。时间间隔的单位可以是分钟、小时、日、月、周的任意组合。以下是crontab的格式:
# 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
2.crontab准备
#查看cron的守护进程是否启动
ps aux | grep cron
#或者
pgrep cron
#若未启动则启动crontab
sudo cron -f &
3.crontab 使用
#编辑计划任务(第一次启动会让选择编辑工具,选择1基本的vim即可)
crontab -e
#查看已添加的计划任务
crontab -l
#删除计划任务
crontab -r