2015-04-03 33 views
0

我一直在使用ubuntu gdrive命令行工具将部分文件推送到Google Drive;然而,最近我写了一个Python脚本,自动进行的过程: (GDrive的命令行:http://www.howopensource.com/2015/01/google-drive-for-ubuntu-linux/Anacron - 不执行gdrive命令的Python子进程

# 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

问题发生在'export GOPATH = $ HOME/go'。使用教程,我将'go'包放在我的主路径下,而不是一个独立于用户的目录;因此,当脚本以“root”身份运行时,发现“go”包时遇到问题。从脚本传递到日志文件的输出不包含未找到'drive'命令的错误。