Linux简单写一个定时任务

一、所用到的命令

cron 、crontab,系统关于定时任务的两个任务

二、编写一个简单的定时任务脚本

5,10,15,20,25,30,35,40,45,50,55,59  *  *  *  *  echo "`date`---  hello" >> ~/1.txt

意思是每小时的5,10,15...分钟都执行最后的命令,打印一句话到用户路径下的1.txt文件内

三、启动定时任务

crontab  ~/tmp/crontest.cron
四、检查文件1.txt

Sat Dec  9 11:50:01 CST 2017---  hello
Sat Dec  9 11:55:01 CST 2017---  hello
Sat Dec  9 11:59:01 CST 2017---  hello
Sat Dec  9 12:05:01 CST 2017---  hello
Sat Dec  9 12:10:01 CST 2017---  hello
Sat Dec  9 12:15:01 CST 2017---  hello
Sat Dec  9 12:20:01 CST 2017---  hello
Sat Dec  9 12:25:01 CST 2017---  hello
Sat Dec  9 12:30:01 CST 2017---  hello
Sat Dec  9 12:35:01 CST 2017---  hello

看得到,每5min都会定时打印出对应的语句

五、其他相关命令

crontab -l  //查看当前用户的定时任务
crontab -r //移除定时任务



猜你喜欢

转载自blog.csdn.net/my_momo_csdn/article/details/78758492