Bash cron作业不像在命令行上那样执行

时间:2015-03-16 20:29:39

标签: bash amazon-s3 cron

我编写了一个bash脚本,它执行python脚本将文件写入目录,然后将该文件发送到Amazon S3。当我从命令行执行脚本时,它执行得很完美,但是当我用cron运行它时,文件会写入目录,但永远不会被发送到S3。我必须对cron做错事。

这是bash脚本:

#!/bin/bash

#python script that exports file to home directory
python some_script.py

#export file created by python to S3
s3cmd put /home/bitnami/myfile.csv s3://location/to/put/file/myfile.csv

就像我之前说的那样,使用./bash_script.sh手动执行工作正常。当我设置cron作业时,文件会写入目录,但永远不会被发送到S3。

我的cron工作是:

18 * * * * /home/bitnami/bash_script.sh

我是否错误地使用了cron?请帮忙。

1 个答案:

答案 0 :(得分:1)

Cron看起来不错,但是找不到.py文件的路径。

您必须添加路径或家庭,如:

location=/home/bitnami/
python $location/some_script.py

还需要正确定位s3cmd:

/bin/s3cmd

替代方案可能还需要在执行脚本之前先加载用户环境,以便为s3cmd找到用户名/密码/ ssh密钥