crontab 执行python、shell脚本注意项
crontab
cron中的环境变量和系统的环境变量是不一样的。
在执行shell脚本和python脚本时,可能会要求指定账户,指定环境运行程序。
shell
- crontab
30 1 * * * zhangsan source /etc/profile && sh /data0/vad/test1.sh >> /tmp/test1.log 2>&1
- 指定账户 zhangsan
- 需要系统环境变量(shell脚本需要) source /etc/profile
- shell执行 sh /data0/vad/test1.sh
python
- crontab
00 1 * * * zhangsan source ~/.bashrc &&python3 /data0/vad/test2.py >> /tmp/test2.log 2>&1
- 指定账户 zhangsan
- 需要系统环境变量(python中linux命令依赖张三环境下的变量【非系统】) source ~/.bashrc
- python执行 python3 /data0/vad/test2.py
参考文献
http://jqyui.com/faq/list.asp?Unid=455
https://www.cnblogs.com/kerrycode/p/11386074.html