Script to start a instance in amazon ec2

This script is used to start a instance in ec2, you can extended this script in the way you want, we keep on posting new scripts to work with ec2

#!/bin/bash

export EC2_HOME=/home/sandeep/ec2/ec2-api-tools-1.3-46266
PATH=$EC2_HOME/bin:$PATH
export EC2_PRIVATE_KEY=/home/sandeep/ec2/pk-XXXXXXXXXXXXXXXXXXXXXXXX.pem
export EC2_CERT=/home/sandeep/ec2/cert-XXXXXXXXXXXXXXXXXXXXXXXX.pem
export EC2_URL=https://us-east-1.ec2.amazonaws.com
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre/

export amiid="ami-0d5db264"
export key="xxxxsshkeyxxxx"
export zone="us-east-1d"
export id_file="/home/sandeep/ec2/keyxxx.pem"
export group="default"

#
# Start the instance
#
echo Launching AMI ${amiid}
${EC2_HOME}/bin/ec2-run-instances ${amiid} -z ${zone}
                         -k ${key} --group ${group}  > /tmp/a
if [ $? != 0 ]; then
   echo "Error starting instance for image" ${amiid}
   exit 1
fi
export iid=`cat /tmp/a | grep INSTANCE | cut -f2`

#
# Loop until the status changes to 'running'
#
sleep 30
echo Starting instance ${iid}
export RUNNING="running"
export done="false"
while [ $done == "false" ]
do
   export status=`${EC2_HOME}/bin/ec2-describe-instances ${iid} | grep INSTANCE | cut -f6`
   if [ $status == ${RUNNING} ]; then
      export done="true"
   else
      echo Waiting...
      sleep 10
   fi
done
echo Instance ${iid} is running

Please feel free to post any comments or errors XX