Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created this bash script to generate a snapshot of my EBS Volume

#! /usr/bin/bash
ec2-create-snapshot -d "My Snapshot" vol-XXXXXXX -O <MyKey> -W <MyOtherKey>

And it works when I run this line in terminal, while connected to the server


Then I created this crontab

0 * * * * (bash ~/../bash/

#0 * * * * ~/../bash/
#0 * * * * (/usr/bin/bash ~/../bash/ 

And I get this message in my email

/home/ec2-user/../bash/ line 4: ec2-create-snapshot: command not found

I'm out of ideas about how to make this work. The problem seems to be that when executed from the crontab, the script is not finding the AWS API Tools.

Any ideas would be very appreciated.

For clarity, here is what ended up working. Thanks for pointing me in the right direction.

Connect to the server and then type echo $EC2_HOME and hit enter.

Then type echo $JAVA_HOME and hit enter.

Then type sudo find / -name "ec2-create-snapshot" (this one might return multiple values)

Make a note of the values that each of these return. You will use them in a minute.

Create this bash script:

#! /usr/bin/bash
export EC2_HOME=/your/ec2_home/path
export JAVA_HOME=/your/java_home/path

# Create an AWS Snapshot
/path/to/your/ec2-create-snapshot -d "Your Snapshot Description" vol-yourvolid -O YOURPUBLICKEY -W YOURPRIVATEKEY

You should be able to execute this by typing bash into the terminal

Then open your cron with contab -e and add this line:

* * * * * (bash ~/your/dir/ #CREATE AWS Snapshot

Hope this helps someone.

share|improve this question
Specify the full path to ec2-create-snapshot. cron runs with a minimal $PATH. – ceejayoz Jan 30 '13 at 17:14
Ah, thanks for posting what finally worked; I forgot that some of the EC2 CLI commands need JAVA_HOME to be set. – gareth_bowles Jan 30 '13 at 21:19
up vote 2 down vote accepted

In addition to specifying the full path to the command as @ceejayoz says in the comments, you'll also need to set EC2_HOME to point to your EC2 tools directory, and you may also need to add $EC2_HOME/bin to your PATH in order for referenced files in the command scripts to be picked up correctly.

Rather than specifying a bunch of environment variables in your crontab, it's neater and more reliable to create a shell script that sets the environment and calls your command, and then call the script from your crontab.

share|improve this answer
My path is (I think) /opt/aws/bin - I am running set EC2_PATH=/opt/aws and keep getting a message now that says "EC2_HOME is not set" - tried searching for help, but can you point me to how to properly set this? – Chris Jan 30 '13 at 18:08
Do echo $EC2_HOME as your normal user and you'll see what it's set to. – ceejayoz Jan 30 '13 at 18:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.