I am using this following script which does a regular backup of volumes on Amazon AWS cloud service. It creates new snapshots of the volumes and should remove snapshots older than two days. It is creating new snapshots just fine but while removing older snapshots, it is not doing it right. #!/bin/bash## File: vol-snapshot.shTODAY=`date +%m-%d-%Y`echo ================================================echo Starting SNAPSHOT creation and deletion process for $TODAYecho echo The script will create a snapshot of every single volumeecho It will delete snapshots older than two daysecho echo Setting ENVIRONMENTAL VARIABLES FOR ec2###export EC2_HOME='/usr/local/ec2'  # Make sure you use the API tools, not the     AMI toolsexport EC2_BIN=$EC2_HOME/binexport EC2_PRIVATE_KEY=$EC2_HOME/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pemexport EC2_CERT=$EC2_HOME/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXX.pemexport REGION=us-east-1dexport PATH=$PATH:$EC2_BINexport OLD=`date +%m-%d-%Y --date '2 days ago'`##### To find the current location of JAVA_HOME, try env | grep JAVA_HOME# It's necessary to put this environment variable in here because# cron will not have access to your standard environment variables.export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64#### Get VolumesVOLUMES=`ec2-describe-volumes | grep VOLUME | cut -f 2`echo The volumes are: $VOLUMESecho echo ====================================echo Creating snapshots of volumes: $VOLUMESecho for volume in $VOLUMESdo   ec2-create-snapshot -C $EC2_CERT -K $EC2_PRIVATE_KEY -d Creating     Snapshots for $TODAY $volumedoneechoecho =====================================echo Deleting snapshots older than two days for $VOLUMESecho for volume in $VOLUMESdoOLDEST=`ec2-describe-snapshots -C $EC2_CERT -K $EC2_PRIVATE_KEY | grep     $volume | grep $OLD | sed -e 's/.*snap/snap/' | sed -e 's/\t.*//'`    if [ x$OLDEST != x ]; then        ec2-delete-snapshot -C $EC2_CERT -K $EC2_PRIVATE_KEY $OLDEST        else        echo No other snapshots to delete using this script.    fidoneecho The end of script.The following line is simply giving snapshots which is just two days old but not the ones beyond that. OLDEST=`ec2-describe-snapshots -C $EC2_CERT -K $EC2_PRIVATE_KEY | grep $volume | grep $OLD | sed -e 's/.*snap/snap/' | sed -e 's/\t.*//'Also, should this be placed under a for loop before if? I would be very pleased if someone can help me out here.
Create and Delete Amazon EC2 Volumes using a shell script
bash;amazon ec2