linux 之实现定时任务

  一.方式一

   (1)命令行 的方法:

  一.方式一   

     需求:每分钟执行一次/etc 目录的添加 到/tmp/a.txt 中

    (1) touch a.txt创建文件

    (2) crotab -e 进行任务的定制 */1 * * * * ls -l /etc/>> /tmp/a.txt

     (3) 查看定时的任务的内容:cat  a.txt     

      查看定时的任务:crontab -l
     (4) 取现定时任务 :crontab  -r  

  二.方式二

    (2)shell 脚本执行定时任务

   方式二
    1.cd /home 中 mkdir mytest1
    
2.cd mytest1 中创建 文件 touch test2.txt
    
3.vim mytt.sh 进行任务的分配编辑      date >>/home/mytest1/test2      cal>>/home/mytest1/test2 (将日历添加到test2 中)     4.进行定时任务 : crontab -e 进行编辑定时任务 */1 * * * * /home/mytest1/mytt.sh 》》》执行入口哦

   

                            

猜你喜欢

转载自www.cnblogs.com/mofujin/p/12070175.html
今日推荐