Question

I'm using bashrc to make and delete snapshots.

To delete them, I wanna use that command:

ec2-describe-snapshots | sort -r -k 5 | awk '{print "Deleting snapshot: " $2}'

and using a grep on the description but when I use grep directly on that command like:

ec2-describe-snapshots | sort -r -k 5 | grep "My Keyword" | awk '{print "Deleting snapshot: " $2}; system("ec2-delete-snapshot " $2)'

It doesn't return anything because it search only on the id of the snapshot, isn't it?

So my question is: How can I search for a keyword that is included in the description on the snapshot?

Was it helpful?

Solution

After looking at your script it looks like it should work. So I tried the same thing in my server but instead of deleting it i'm just going to describe the snapshots again.

ec2-describe-snapshots | sort -r -k 5 | grep <description> | awk '{print "Deleting snapshot: " $2}; system("ec2-describe-snapshots " $2)'

The response I get is like this

Deleting snapshot: snap-fabaa29e
SNAPSHOT        snap-fabaa29e   vol-cccb4ea6    completed       2012-01-31T16:08:42+0000        100%    362457333706    50      <description>
Deleting snapshot: snap-ccbaa2a8
SNAPSHOT        snap-ccbaa2a8   vol-b2cb4ed8    completed       2012-01-31T16:08:42+0000        100%    362457333706    50      <description>
Deleting snapshot: snap-c0baa2a4
SNAPSHOT        snap-c0baa2a4   vol-d0cb4eba    completed       2012-01-31T16:08:42+0000        100%    362457333706    50      <description>

The grep portion of the command is working fine. But its possible there's something wrong with the description you're searching for. Also i'm not sure why you're sorting the results, is it not the same to delete all of them or do you have to delete the drives in a certain order?

Double check the text in your grep clause. Pretty sure you'll find an error there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top