简体   繁体   English

python中的谷歌电子表格阅读脚本不是从cron计划运行而是在我运行shell命令时工作

[英]google spreadsheet reading script in python not running from cron schedule but working when i am running it shell command

I am reading data from Google spreadsheet by using python script, the script is working fine when I am running using the shell command but it has not worked when i scheduled it on cron.我正在使用 python 脚本从 Google 电子表格中读取数据,当我使用 shell 命令运行时,该脚本工作正常,但是当我在 cron 上安排它时它没有工作。

so far in check list that i have done到目前为止,在我完成的检查清单中

  1. file name and location related no issue available文件名和位置相关没有问题可用
  2. by using tail -f /var/log/syslog | grep CRON通过使用tail -f /var/log/syslog | grep CRON tail -f /var/log/syslog | grep CRON this command i have seen that schedule is fired on time tail -f /var/log/syslog | grep CRON这个命令我已经看到计划按时触发

  3. I have added my script method in a different script which is running fine from cron but still that method not worked in times of cron running我已经在另一个脚本中添加了我的脚本方法,该脚本在 cron 中运行良好,但该方法在 cron 运行时仍然不起作用

cron statement cron 语句

/home/ubuntu/.virtualenvs/python_3.5/bin/python /location/script_name.py

Is there any other way to check this why it is not working from cron schedule but working fine from shell command.有没有其他方法可以检查为什么它不能从 cron 计划工作但从 shell 命令正常工作。

After getting the suggestion from @stovfl i added >> /tmp/cron.log 2>&1 this line从@stovfl 得到建议后,我添加了>> /tmp/cron.log 2>&1这一行

/home/ubuntu/.virtualenvs/python_3.5/bin/python /location/script_name.py  >> /tmp/cron.log 2>&1

with my cron statement and check the log file and i found i have not used explict path for authentication json file though it is inside project folder so times of shell command it it was working fine.使用我的 cron 语句并检查日志文件,我发现我没有使用身份验证 json 文件的显式路径,尽管它在项目文件夹中,所以 shell 命令它工作正常。 used code just like below使用如下代码

credentials = ServiceAccountCredentials.from_json_keyfile_name('file_name.json')

and therefore when cron fired the scrip it failed to get the authetication file location and not ran.因此,当 cron 触发脚本时,它无法获取身份验证文件的位置并且没有运行。 then i changed like below然后我改变了如下

credentials = ServiceAccountCredentials.from_json_keyfile_name('location_of_file/file_name.json')

now it works like a charm from cron and shell command现在它就像 cron 和 shell 命令的魅力一样

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

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