【问题标题】:Run s3cmd sync via python script & cron通过 python 脚本和 cron 运行 s3cmd sync
【发布时间】:2013-07-28 01:53:28
【问题描述】:

我这几天一直在努力解决这个问题,希望能得到一些帮助 --

基本上,我编写了以下 Python 脚本

import os, sys

# =__=__=__=__=__=__=__ START MAIN =__=__=__=__=__=__=__
if __name__ == '__main__':

# initialize variables
all_files = []

# directory to download data siphon files to
dDir = '/path/to/download/directory/'

# my S3 bucket
s3bucket = "com.mybucket/"

foldername = "test"

# get a list of available feeds
feeds = <huge JSON object with URLs to feeds>

for item in range(feeds['count']):
    # ...check if the directory exists, and if not, create the directory...
    if not os.path.exists(folderName):
        os.makedirs(folderName)

    ... ... ...

    # Loop through all the splits
    for s in dsSplits:
        ... ... ...
        location = requestFeedLocation(name, timestamp)

        ... ... ...
        downloadFeed(location[0], folderName, nameNotGZ)

    # THIS IS WHERE I AM HAVING PROBLEMS!!!!!!!!!!!
    cmd = 's3cmd sync 'dDir+folderName+'/ s3://'+s3bucket+'/'
    os.system(cmd)

我的代码中的所有内容都有效...当我直接从命令行运行时,一切都按预期运行...但是,当我通过 cron 执行它时——以下内容不执行(其他所有内容都执行)

# THIS IS WHERE I AM HAVING PROBLEMS!!!!!!!!!!!
cmd = 's3cmd sync 'dDir+folderName+'/ s3://'+s3bucket+'/'
os.system(cmd)

回答几个问题,我以root身份运行cron,为root用户配置s3cmd,操作系统是Ubuntu 12.04,python版本是2.7,所有必要的目录都具有读/写权限...

我错过了什么?

【问题讨论】:

  • 从 cron 运行任何内容的最安全方法是始终使用任何命令的完整路径:尝试将 s3cmd 替换为 /usr/local/bin/s3cmd 或安装了 s3cmd 的任何位置。
  • 我认为成功了!!!谢谢佩德罗!!

标签: python cron ubuntu-12.04 sync s3cmd


【解决方案1】:
  1. 首先在命令中检查变量“文件夹名”,您在变量中使用了 N。
  2. 在命令语法中,您需要添加加号 (+) 符号前缀,例如 +dDir+folderName+

所以我希望命令如下所示..

cmd = 's3cmd sync '+dDir+文件夹名+'/s3://'+s3bucket+'/'

os.system(cmd)

在这里我找到了更多 s3cmd 同步帮助:http://tecadmin.net/s3cmd-file-sync-with-s3bucket/

【讨论】:

    猜你喜欢
    • 2011-03-27
    • 2019-07-23
    • 2021-11-21
    • 2019-12-24
    • 2015-03-16
    • 2017-08-11
    • 2016-10-01
    • 2014-06-20
    • 1970-01-01
    相关资源
    最近更新 更多