【问题标题】:Anacron - Python subprocess not executing gdrive commandAnacron - Python 子进程不执行 gdrive 命令
【发布时间】:2015-06-08 23:30:20
【问题描述】:

我一直在使用 ubuntu gdrive 命令行工具将我的一些文件推送到 Google Drive;但是,最近我编写了一个自动化该过程的 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 Drive。这是我的 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

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

【问题讨论】:

    标签: python ubuntu cron


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 2019-03-06
      • 2019-06-21
      • 2017-05-30
      相关资源
      最近更新 更多