简体   繁体   English

python 脚本没有从 cron 运行

[英]python script not running from cron

It runs by hand when I execute:当我执行时它手动运行:

python /var/lib/mongodb/script.py >> /var/lib/mongodb/script.log 2>&1

But using cronjob, I see that script is executed but no output in /var/lib/mongodb/script.log但是使用cronjob,我看到脚本被执行但在/var/lib/mongodb/script.log中没有输出

sudo -u mongodb crontab -l
* * * * * python /var/lib/mongodb/script.py >> /var/lib/mongodb/script.log 2>&1

on /var/log/syslog I see that cron is executed but no output in /var/lib/mongodb/script.log and the script.py is not running.在 /var/log/syslog 上,我看到 cron 已执行,但 /var/lib/mongodb/script.log 中没有输出,并且 script.py 未运行。

Update:更新:

I tried with a test.py script and is working:我尝试使用 test.py 脚本并且正在工作:

root@jessie:~# ls -al /var/lib/mongodb/test.py -rw-r--r-- 1 root root 184 May 10 13:49 /var/lib/mongodb/test.py

root@jessie:~# sudo -u mongodb crontab -e * * * * * python /var/lib/mongodb/test.py >> /var/lib/mongodb/test.log 2>&1

May 10 14:02:01 jessie CRON[1889]: (mongodb) CMD (python /var/lib/mongodb/test.py >> /var/lib/mongodb/test.log 2>&1)

root@jessie:~# ls -al /var/lib/mongodb/test.log -rw-r--r-- 1 mongodb nogroup 1792 May 10 14:04 /var/lib/mongodb/test.log

The test.py script contains: test.py 脚本包含:

print "Hello World!" print "Hello Again" print "I like typing this." print "This is fun." print 'Yay! Printing.'

Your .py file is not executable;您的.py文件不可执行; use chmod +x and try to run cron job again.使用chmod +x并尝试再次运行 cron 作业。

Similar case here .类似的情况在这里 Making file executable helped.使文件可执行有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM