通过crontab执行python脚本
我的 python 脚本不会每分钟都通过 crontab 运行,会发生什么情况。 我的脚本具有执行权限,然后调用 python 中的另外两个脚本。
This is the content of my crontab (#crontab -l):
*/1 * * * * /usr/bin/rsm/samplesMonitor.py
Thank you guys.what happens to my script in python that does not run through crontab every minute.
My script has execute permissions and then calls two other scripts in python.
This is the content of my crontab (#crontab -l):
*/1 * * * * /usr/bin/rsm/samplesMonitor.py
Thank you guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查
/var/log/syslog
是否有错误。更新:根据您的日志消息,脚本正在运行,但返回错误代码。如果您安装了邮件代理,Cron 会将输出通过电子邮件发送给您。
尝试以下任一方法:
apt-get install exim4
更改您的 cron 行以记录到文件,如下所示:
更新 2: 我重新阅读了您的问题,我发现您可能遇到了 python 导入问题。你说你的脚本调用了另外两个脚本。我的建议是测试从
/
运行脚本。 Python 的默认行为是在当前工作目录中查找导入,因此请确保您的脚本可以从任何路径位置运行。在 crontab 中,您可以通过从另一个 shell 进程中调用脚本来设置起始工作目录。例如:
Check
/var/log/syslog
for errors.Update: According to your log message, the script is running but returning an error code. Cron will email you the output, if you have a mail agent installed.
Try either:
apt-get install exim4
change your cron line to log to file, like so:
Update 2: I re-read your question and it acurred to me that maybe you are running into python import issues. You say that your script calls two other scripts. My suggestion would be to test running your script from
/
. Python has a default behavior to find imports in the current working directory, so make sure your script can run from any path location.In the crontab, you can set the starting working directory by calling your script from within another shell process. For example:
我相信它应该是
*/1
,而不是*\1
。I believe it should be
*/1
, not*\1
.它应该是
*/1
而不是*\1
(正斜杠而不是反斜杠)。另外,请确保路径正确; /usr/bin 下通常没有子目录。It should be
*/1
instead of*\1
(forward slash instead of backslash). Also, make sure the path is correct; there usually are no subdirectories under /usr/bin.如果你想让它每分钟运行一次,就这样做
If you want it to run every minute, just do this