我一直在使用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脚本运行,但似乎不正确地运行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
未报告任何错误;有谁有想法?
答案 0 :(得分:1)
问题发生在居住和出口GOPATH = $ HOME / go'。使用教程,我放置了' go'在我的主路径下打包而不是与用户无关的目录;因此,当脚本作为' root'时,它有问题找到' go'包。从脚本传递到日志文件的输出不包含'驱动器'命令未找到。