user7966536
user7966536

Reputation:

bash script doesn't work through crontab

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)

Upvotes: 1

Views: 2011

Answers (2)

Joao Vitor Deon
Joao Vitor Deon

Reputation: 147

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

Upvotes: 3

arun singh
arun singh

Reputation: 21

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

Upvotes: 1

Related Questions