linux定时执行脚本

每天清晨 4:00:01,用python执行/opt/aa.py文件。

编辑定时任务:

#crontab -e 

加入:

0 4 * * * python /opt/aa.py

保存,退出即可。

如果执行的文件在当前目录的二级目录下,则需要先cd进入相应目录,再python:

*/5 * * * * cd /home/iris/; python aa.py

crontab命令格式:

* * * * * command M H D m d command

M: 分(0-59) H:时(0-23) D:天(1-31) m: 月(1-12) d: 周(0-6) 0为星期日

* 代表取值范围内的数字 / 代表"每" - 代表从某个数字到某个数字 , 代表离散的取值(取值的列表)

示例:

编辑python文件:

ccc="tttt.txt"

f.open(ccc,'a')

f.write("hello!")

f.close

保存为hello.py并退出。

crontab -e

*/1 * * * * python /home/zengzichun/hello.py

保存并退出。不久即可看到目录下多了tttt.txt文件,打开可看到"hello!hello!......" 。

 

crontab定时清理日志文件:

  https://www.cnblogs.com/think-in-java/p/5712197.html

 

参考博客:http://blog.csdn.net/chenggong2dm/article/details/12649053

更详细的介绍:https://www.cnblogs.com/huidaoli/articles/4635143.html

posted @ 2015-01-20 11:20  Iris ^  阅读(14005)  评论(0编辑  收藏  举报