Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to run a script on an ec2 instance once a day, and I'd like to have some easy way for it to let me know if something went wrong.

I would prefer not to have to modify the original image, which is a recent version of Ubuntu, so ideally I'd like to do all setup in the script I pass to the Ubuntu instance through the ec2-run-instances command.

I've considered creating a gmail account for it, and letting it send email through that - but the setup was rather involved, with certificates and such things.

I've looked at using the gist API, but anything uploaded through it is public.

The Google command line tool also appears quite complicated to set up.

Is there some easier way to do this?

share|improve this question
    
It sounds like you have some privacy requirements on the status information; can you add some more details on that? –  gareth_bowles Oct 2 '10 at 1:11
add comment

3 Answers

Perhaps the easiest way to monitor the success or failure of this is to do log analysis. So your script (whether it's run from cron, or some other mechanism) can log its output to some local log file. Then, from a machine you control outside of the Amazon cloud, you log onto each ubuntu instance remotely and analyze the logs. For example:

ec2_hosts=`ec2-describe-instances | awk '/INSTANCE/ { print $4 }'`
for host in $ec2_hosts; do
    ssh -i ~/.ssh/SSHKey.pem ubuntu@$host \
        "grep 'something' /var/log/my_script.log" > my_local_status.log
done

# Look through "my_local_status.log" to see the results

This doesn't require any special configuration on the part of your instance, and you can monitor as many EC2 instances as you have running.

share|improve this answer
add comment

Use the built in linux functions for this. If you're running a shell script anyway, any modification you need to make to the box can be done as part of the script. Having your script log to a file on the instance and then email you that log file should be really easy.

I am not familiar with the Ubuntu instances, but it should have basic mail handling programs installed. This is over simplified, but your script could do something like this:

which mail || apt-get install mailx
cat $logfile | mail your@address.com -s "Report on x from ec2 script"
share|improve this answer
add comment

What if your app creates a log file (a website). Then you can use one of the free website monitoring services such as AlertFox or Pingdom to alert you if that pages contains the word "error".

share|improve this answer
add comment

Your Answer

 
discard

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