Bash cron作业无法像在命令行上那样执行 [英] Bash cron job doesn't execute like it does on command line
问题描述
我编写了一个bash脚本,该脚本执行python脚本以将文件写入目录,然后将该文件发送到Amazon S3。当我从命令行执行脚本时,它会完美执行,但是当我使用cron运行该脚本时,该文件将写入目录,但永远不会发送到S3。我一定对cron做错了。
I've written a bash script that executes a python script to write a file to a directory, then sends that file to Amazon S3. When I execute the script from the command line it executes perfectly, but when I run it with cron, the file writes to the directory, but never gets sent to S3. I must be doing something wrong with 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
$ b就像我之前说的那样,
$ b
使用 ./ bash_script.sh
手动执行可以正常工作。当我设置cron作业时,文件将写入目录,但从未发送到S3。
Like I said before, manually executing works fine using ./bash_script.sh
. When I set up the cron job, the file writes to the directory, but never gets sent to S3.
我的cron作业是:
18 * * * * /home/bitnami/bash_script.sh
我不正确地使用cron?请帮忙。
Am I using cron incorrectly? Please help.
推荐答案
Cron看起来不错,但是找不到.py文件的路径。
Cron looks OK, however your path to the .py file will not be found.
您将必须添加路径或房屋,例如:
You will have to add a path or home like:
location=/home/bitnami/
python $location/some_script.py
还需要正确定位s3cmd:
Also s3cmd needs to be located correctly:
/bin/s3cmd
替代方案可能还需要先加载用户环境,然后再执行脚本以查找s3cmd的用户名/密码/ ssh密钥
Alternative might also need to load your user environment first before executing the script to find username/password/ssh key for s3cmd
这篇关于Bash cron作业无法像在命令行上那样执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!