【发布时间】: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