Mike McCormick
Mike McCormick

Reputation: 121

Scheduling an ec2-create-image cron job

I originally posted this on the AWS forums and didn't get much response.

I'm trying to schedule a twice daily image of a server, I'm using this entry in my crontab under the root user:

01 12,00 * * * /opt/aws/bin/ec2-create-image i-InstanceNameHere --region eu-west-1 --name `date +%s` --description "testing-imaging" --no-reboot -O ABCDEFGHIJKLMNOPQRS -W ABCDEFGHIJKLMNOPQRS

Running the command (with correct key information and instance name of course) manually successfully creates an image (but without the description), however when cronned nothing happens.

I've both had this command directly in crontab and have dropped the above command into a bash script which also pops out an entry in a file with a date stamp each time it runs, so I'm certain this isn't a cron issue.

Does anyone have any thoughts what could cause this to not work when scheduled?

Thanks in advance for any advice!

Mike

Upvotes: 0

Views: 276

Answers (2)

Mike McCormick
Mike McCormick

Reputation: 121

The problem, as suspected, wasn't specifically do to with cron.

Off the back of error2007s's query for logs, I put everything into a bash script and pushed all output into a log file.

The issue was that when running through cron, most of the server variables needed weren't set, in the end I'm left with the below list definitions. These might be a bit overzelous, but in the end the process works.

#!/bin/sh

#Set required envionmental variables for ec2-create-image to run
export AWS_PATH=/opt/aws
export PATH=$PATH:$AWS_PATH/bin
export AWS_ACCESS_KEY=000000000000
export AWS_SECRET_KEY=000000000000000000000
export AWS_HOME=/opt/aws/apitools/ec2
export EC2_HOME=/opt/aws/apitools/ec2
export JAVA_HOME=/usr/lib/jvm/jre

/opt/aws/bin/ec2-create-image i-123123123123123 --region eu-west-1 --name `date +%s` --description "testing-imaging" --no-reboot &>> backuplog.txt

echo "backup operation ran `date`" >> backuplog.txt

Upvotes: 0

Piyush Patil
Piyush Patil

Reputation: 14543

Cron runs on a 24 hour clock starting from 0 as midnight and 23 as 11 pm. As such you'd simply have to replace 12,0 with 0,12. Also just use single "0".

Upvotes: 1

Related Questions