通过python脚本&运行s3cmd同步cron的

时间:2013-07-28 01:53:28

标签: python cron ubuntu-12.04 sync s3cmd

我一直试图解决这个问题好几天了,并希望得到一些帮助 -

基本上,我编写了以下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执行它时 - 以下不执行(其他所有操作)< / p>

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

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

我错过了什么?

1 个答案:

答案 0 :(得分:2)

  1. 首先检查变量&#39; foldername&#39;在命令中你已经在变量中使用了N.
  2. 在命令语法中,您需要在+ dDir + folderName +
  3. 前缀中加上加号(+)

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

      

    cmd =&#39; s3cmd sync&#39; + dDir + foldername +&#39; / s3://&#39; + s3bucket +&#39; /&#39;

         

    使用os.system(CMD)

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