Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS not working working from Cronjob

So I have a script to download a file from AWS daily and append it to a spread sheet. To do this I have set up a cronjob.

The Script works fine when I run it manually, but does not work when running from the cronjob.

The code has a line:

aws s3 cp s3://My/files/backup/ ~/home/AnPoc/ --recursive --exclude "*.tgz" --include "*results.tgz" 

And in the email I recieve from the cronjob execution, I see the following error message:

./AnPoc/DayProcessing.sh: line 14: aws: command not found 

I don't know why the command is not being found. Any help would be great.

like image 397
AnPocArBuile Avatar asked Oct 21 '14 07:10

AnPocArBuile


People also ask

Why is Cronjob not working?

Crontab might fail for a variety of reasons: The first reason is that your cron daemon might not be working for any reason, resulting in your crontab failing. There also exists a possibility that your system's environment variables are not settled correctly.

How do I view crontab logs on Amazon Linux?

Finding cron logs on CentOS and Redhat On CentOS, Redhat and Amazon Linux cron logs are written to /var/log/cron . You will likely require root/sudo privileges to access your cron logs.


2 Answers

First: check where on your system the executable aws is stored. Use this command:

$ which aws /usr/bin/aws # example output, can differ in your system 

Now, place a variable called $PATH in your crontab before the script:

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

Those paths separated by : define where should be search for the exectable. In the example above it's /usr/bin. You have to check all executables in your cron job that they are available.

Another thing: try to avoid path with a tilde (~) in cronjobs. Use /home/user instead.

like image 179
chaos Avatar answered Oct 13 '22 23:10

chaos


You should use the full path for the aws command. For example, /usr/local/bin/aws

like image 31
libregeek Avatar answered Oct 14 '22 00:10

libregeek