1
我一直想麻煩這幾天,現在,希望得到一些幫助s3cmd同步 -運行通過Python腳本及cron的
基本上,我寫了下面的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,s3cmd爲root用戶配置,OS爲Ubuntu 12.04,python版本爲2.7,所有必需的目錄都具有讀/寫權限...
我錯過了什麼?
從cron運行任何東西最安全的方法是始終使用任何命令的完整路徑:嘗試用'/ usr/local/bin/s3cmd'或s3cmd'安裝s3cmd'替換's3cmd'。 –
我覺得這個伎倆!謝謝佩德羅! –