0
votes

I am running a bash script that transfers files to my AWS bucket.If i run the bash script through my terminal it works fine (via ./myBash.sh). However I put it in my crontab but there it doesn't work.This is my bash script

#!/bin/bash

s3cmd put /home/anonymous/commLogs.txt s3://myBucket/

echo transfer completed

echo now listing files in the s3 bucket

s3cmd ls s3://myBucket/

echo check

And this is my crontab-

SHELL=/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

46 13 * * * /bin/bash myBash.sh

And here is a list of things i have aready tried -

1)tried running the crontab with a node app to test whether crontab was working(the answer was yes)

2)tried running the crontab without the SHELL and PATH

3)Tried running the bash script from cron using sudo (46 13 * * * sudo myBash.sh)

4)tried running the bash without the /bin/bash

5) Searched many sites on the net for an answer without satisfactory results

Can anyone help me with what the problem may be?(I am running Ubuntu 14.04)

2
Did you output the stdout of the script from the cron to a file what was the contents of that file? (46 13 * * * /bin/bash myBash.sh > /home/anonymous/cron_out.txt) - James Brown
This script was just to test whether that crontab was executing the bash or not..so the contents of the txt file were just "abcdefgh" - user7966536
So you did not. And did you exclude the path to your script in the cron like above? - James Brown
The bash script is the /bin folder - user7966536
If it is in the path, give it execution rights with chmod and remove the /bin/bash part from your crontab, ie. 46 13 * * * myBash.sh. - James Brown

2 Answers

2
votes

After a long time getting the same error, I just did this :

SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin


* * * * * /bin/bash /home/joaovitordeon/Documentos/test.sh
1
votes

For anyone coming to this post. I was having same problem and reason was crontab was running under root user and s3cmd was configured under ubuntu user. so need to copy .s3cfg to root

cp -i /home/ubuntu/.s3cfg /root/.s3cfg