3

I am trying to run a backup script on my ec2 amazon server (ubuntu 14.04), to automatically create a snapshot of amazon ebs volumes. Therefore I am using the aws-missing-tools script: https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup

This my backup script, that triggers ec2-automate-backup-awscli.sh:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/aws
HOME=/
JAVA_HOME=/usr/lib/jvm/default-java/jre/
MAILTO=xxx.xxxxxx@me.com

AWS_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxx
AWS_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/opt/aws/ec2-automate-backup-awscli.sh -r us-east-1 -s tag -t 'Backup,Values=true' -k 31 -p

But i only get this error when scheduling this script with crontab:

26 23 * * * /opt/aws/backup.sh >> /var/log/aws.log 2>&1

Log file: "In order to use ec2-automate-backup-awscli.sh, the executable "aws" must be installed."

Directly executing "sh backup.sh" works fine. (snapshots are created.)

Any ideas?

3 Answers3

5

Your PATH variable should be a list of directories, so given that your aws executable lives at /usr/local/bin/aws, your PATH should be this:

/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

Also, you're better off setting the shell via a "hashbang" like so, rather than using the SHELL environment variable, as this will allow crontab to automatically use the correct interpreter:

#!/bin/bash
Craig Watson
  • 9,790
0

I had this exact error. Assuming that you have the prerequisites installed and that running the command manually works, but not in Cron, it may be that the correct path is not exposed to the cron command. You can fix this by running crontab -e and then entering the path directly into the cron tab:

# Export the path so that the scripts run correctly PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin

-1

The dot character is not allowed in the filename of a cron script unless 14.04 truly has enabled Linux Standards Base, just A-Za-z0-9- - see this Launchpad Bug for more info

Rename "backup.sh" to "backupsh".

A better test than "sh backup.sh" would be "run-parts --verbose /opt/aws/". If run-parts does not show your filename, the cron will not run it.

Craig Watson
  • 9,790
rjt
  • 594