ubuntu 定时任务 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

crontab -l 在标准输出上显示当前的crontab。 
crontab -r 删除当前的crontab文件。 

crontab -e 选编号3vim 编辑当前的crontab文件。当结束编辑离开时,编辑后的文件将自动安装。 


例子:

每天早上2点  
0       2  * * * echo "Good morning." >> /tmp/test.txt //注意单纯echo,从屏幕上看不到任何输出,因为cron把任何输出都email到root的信箱了。
分钟  小时
每两个小时 

0   */2   * * * echo "Have a break now." >> /tmp/test.txt  

每天的下午4点、5点、6点的5 min、15 min、25 min、35 min、45 min、55 min时执行命令。 
5,15,25,35,45,55 16,17,18 * * * command


猜你喜欢

转载自blog.csdn.net/weixin_41607151/article/details/80671891