每天清晨 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