简体   繁体   English

通过python脚本和cron运行s3cmd sync

[英]Run s3cmd sync via python script & cron

I've been trying to trouble this for days now, and would appreciate some help -- 我几天来一直在努力解决这个问题,希望能有所帮助-

Basically, I wrote the following Python script 基本上,我编写了以下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)

Everything in my code works...when I run this straight from the command line, everything runs as expected...however, when I have it executed via cron -- the following DOES NOT execute (everything else does) 代码中的所有内容都可以正常运行...当我从命令行直接运行时,所有内容均按预期运行...但是,当我通过cron执行它时,以下代码不执行(其他所有操作都可以)

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

To answer a few questions, I am running the cron as root, s3cmd is configured for the root user, OS is Ubuntu 12.04, python version is 2.7, all of the necessary directories have Read / Write permissions... 为了回答一些问题,我以root用户身份运行cron,为root用户配置了s3cmd,操作系统是Ubuntu 12.04,python版本是2.7,所有必需的目录都具有读/写权限...

What am I missing? 我想念什么?

  1. First check variable 'foldername' in command you have used N in variable. 首先在命令中使用变量N来检查变量“ foldername”。
  2. In command syntax you need to add plus (+) sign in prefix like +dDir+folderName+ 在命令语法中,您需要添加加号(+)登录前缀,例如+ dDir + folderName +

So I hope command would be like below.. 因此,我希望命令如下所示。

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

os.system(cmd) 使用os.system(CMD)

Here I found some more s3cmd sync help: http://tecadmin.net/s3cmd-file-sync-with-s3bucket/ 在这里,我发现了更多s3cmd同步帮助: http : //tecadmin.net/s3cmd-file-sync-with-s3bucket/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM