我正处于ubuntu服务器的学习阶段。我有一个python脚本,每天早上都会向我发送天气,当我从命令行运行它时,该脚本运行正常。但是,当我尝试设置crontab条目时,它不起作用。以下行是我放入crontab文件的内容:
30 11 * * * cd /home/ubuntu/documents && /usr/bin/python /home/ubuntu/documents/weatherText.py
我也尝试了以下内容:
30 11 * * * /usr/bin/python /home/ubuntu/documents/weatherText.py
当我在终端中输入以下任一命令时,我的python脚本效果很好。
1.) cd /home/ubuntu/documents && /usr/bin/python /home/ubuntu/documents/weatherText.py
2.) /usr/bin/python /home/ubuntu/documents/weatherText.py
它必须是cron的问题,对吧?感谢您的时间,如果您现在正在查看。
答案 0 :(得分:0)
要确切地知道问题是什么,请在.sh
中编写命令在你的情况下:
<强> myscript.sh 强>
#!/bin/bash
set -x
cd /home/ubuntu/documents
/usr/bin/python /home/ubuntu/documents/weatherText.py
使用set -x
所有命令都在控制台中打印。
然后使用cron:
执行脚本30 11 * * * /fullpathscript/myscript.sh > /anypath/cronlog.log 2>&1
将自动创建/anypath/cronlog.log
。
这个日志显示了你的脚本逻辑的确切错误。