1

I've created a snapshot using ec2-api-tools of a volume within my AWS EC2 account. Currently I have:

>> ec2addsnap vol-xxxxxxxx -d 'My-first-Snapshot'
SNAPSHOT snap-12345678 vol-xxxxxxxx pending 2013-01-30T17:09:35+0000 086018780037 8 My-first-Snapshot

What I want to do is add a --tag Name='Name Tag' to this newly created snapshot from the snap-12345678 id in the response.

This works>

>> ec2addtag snap-12345678 --tag Name='Name Tag'

How can I automate this? I've started writing a simple shell script - but I'm not sure how I would query the response from the initial ec2addsnap to grab the newly created snapshot id in order to apply ec2addtag? Cheers (Thought I was posting this in Serverfault - my apologies)

williamsowen
  • 477
  • 1
  • 7
  • 22

1 Answers1

3

I managed to solve this via the use of awk. My Bash Script =

today=$(date +"%d-%m-%Y")
tagname=$2
ec2addsnap vol-$1 -d $2'-'$today; 
ec2dsnap | grep $2'-'$today | awk -v tagname=$tagname '{print "Adding Tag too: " $2}; system("ec2addtag "$2" --tag Name=\""tagname"\"")';
williamsowen
  • 477
  • 1
  • 7
  • 22