简体   繁体   English

Anacron-Python子进程未执行gdrive命令

[英]Anacron - Python subprocess not executing gdrive command

I have been using the ubuntu gdrive command line tool to push some of my files to Google Drive; 我一直在使用ubuntu gdrive命令行工具将某些文件推送到Google云端硬盘; however, recently I wrote a python script that automates the process: (gdrive command line: http://www.howopensource.com/2015/01/google-drive-for-ubuntu-linux/ ) 但是,最近我写了一个Python脚本来自动化该过程:(gdrive命令行: http : //www.howopensource.com/2015/01/google-drive-for-ubuntu-linux/

# Push to Google Drive
str_output = "\tPushing "
cmd_push = ("drive push -ignore-conflict {0}/").format(dir_db_full)
if dict_args['type'] == now:
    str_output += "zip file "
    cmd_push += zip_db
else:
    str_output += ("\"{0}\" directory ").format(dict_args['type'])
    cmd_push += dir_final + "/"
str_output += "to Google Drive..."
print str_output

cmd_push = ('export GOPATH=$HOME/go ; export PATH=$PATH:$GOPATH/bin ; yes | {0} ').format(cmd_push)
subprocess.call( cmd_push, shell=True)

This works! 这可行!

When I run it via anacron, the whole python script runs, but seems to improperly run the subprocess.call; 当我通过anacron运行它时,整个python脚本都运行了,但是似乎不正确地运行了subprocess.call;。 as in, it does not push the file to Google Drive. 因为它不会将文件推送到Google云端硬盘。 Here is my anacron file: 这是我的anacron文件:

# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

# These replace cron's entries
1       5       cron.daily      run-parts --report /etc/cron.daily
7       10      cron.weekly     run-parts --report /etc/cron.weekly
7       1       week          sudo /usr/bin/python /srv/bin/backup.py -type week >> /srv/bin/log/log_backup.txt
@monthly 20     month         sudo /usr/bin/python /srv/bin/backup.py -type month >> /srv/bin/log/log_backup.txt
@monthly        15      cron.monthly    run-parts --report /etc/cron.monthly

No errors are reported; 没有错误报告; anyone have an idea? 有人有主意吗?

The issue happened to reside 'export GOPATH=$HOME/go'. 问题恰好位于“ export GOPATH = $ HOME / go”。 Using a tutorial, I placed the 'go' package under my home path instead of a directory that was user-independent; 通过使用教程,我将“ go”包放置在主目录下,而不是与用户无关的目录下。 hence, when the script ran as 'root', it had issues finding the 'go' package. 因此,当脚本以“ root”身份运行时,在查找“ go”包时遇到了问题。 The output passed from the script to the log file did not contain the error that the 'drive' command was not found. 从脚本传递到日志文件的输出不包含以下错误:找不到“ drive”命令。

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

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