s3cmd not working as cron-task when echos/dates are added

2.6k views Asked by At

I have a Digital Ocean Droplet (VPS) running Ubuntu 14.04. I have installed s3cmd and am able to run a sync successfully with this command:

s3cmd sync --recursive --preserve /srv s3://MY-BUCKET-NAME

And if I put that same command in to a .sh to run as a cron-task every minute, it works:

* * * * * sh /srv/backupToS3.sh >> /srv/backupToS3.log

But when I add some echos and dates to the .sh:

echo 'Started:'
date +'%a %b %e %H:%M:%S %Z %Y'
s3cmd sync --recursive --preserve /srv s3://MY-BUCKET-NAME
echo 'Finished:'
date +'%a %b %e %H:%M:%S %Z %Y'

the s3cmd sync does not work/run anymore. But the echos and dates print to the log file:

Started:
Mon Jun  8 17:45:01 PDT 2015
Finished:
Mon Jun  8 17:45:01 PDT 2015

Any help or push in the right direction would be very appreciated. I originally followed this article to get this far.

2

There are 2 answers

14
300D7309EF17 On BEST ANSWER

s3cmd uses a configuration file located at ~/.s3cfg. It's probably having trouble picking that up. Pass in --config=/home/username/.s3cfg and see if that helps.

In any case, s3cmd isn't consistently maintained. The official commandline client (aws-cli) is much better in many ways.


edit: use this as your .sh file, make sure it has the executable bit set (chmod 755 whatever.sh).

echo 'Started:'
date +'%a %b %e %H:%M:%S %Z %Y'
/usr/bin/s3cmd sync --recursive --preserve --config=/usr/bin/s3cmd --verbose /srv s3://MY-BUCKET-NAME
echo 'Finished:'
date +'%a %b %e %H:%M:%S %Z %Y'
0
gcommit On

i had the same problem and i tried to figure out why it is not running. My solution was to add the following lines to the top of my script:

export HOME=/home/$USERNAME cd /home/$USERNAME

Also you should call the s3cmd with:

/usr/bin/s3cmd

OR put the following line to the top of your script:

PATH=$PATH:/usr/bin