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

Anacron - Python subprocess not executing gdrive command

我一直在使用 ubuntu gdrive 命令行工具将我的一些文件推送到 Google 驱动器;然而,最近我写了一个 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)

这有效!

当我 运行 它通过 anacron 时,整个 python 脚本 运行s,但似乎 运行 subprocess.call 不正确;如,它不会将文件推送到 Google 驱动器。这是我的 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

没有报错;有人有想法吗?

问题恰好存在于 'export GOPATH=$HOME/go'。使用教程,我将 'go' 包放在我的主路径下,而不是用户独立的目录下;因此,当脚本 运行 为 'root' 时,它无法找到 'go' 包。从脚本传递到日志文件的输出不包含 'drive' 命令未找到的错误。