Jump to content
Updated Privacy Statement
  • 0

a little scripting help greatly appritiated


Filip Fronczak

Question

If I run this command:

 

xe vbd-list vdi-uuid=$(xe vdi-list other-config=ctxs-pool-backup:\ true params=uuid --minimal) params=uuid --minimal

 

I receive as a result a list of uuids like this:


01a2aa7f-f0dd-75b5-7cb3-9c5c2a801877,6e1cab4a-d7d7-b141-e16d-7786dd51063c,89461690-5be8-117b-620d-f14482273054,db4f6456-c059-99d7-c797-49bad583faea,062cc4fb-cee0-5fc0-6255-88764aae5707,7e64119a-7169-efef-88e1-5efc7033606b,287dc05c-f0fc-e3f0-dd89-30e316cadea3,4b5ff655-d938-a7a1-da5a-0ad9e7b5b477,70e17ebd-b8db-3557-20b7-6b8c43b85c56,63928e76-f650-e3de-bed2-ba94dac2de5a,cc3cada7-e5b6-c433-7125-6c7661e61478,520d1844-316d-fbf1-45e2-7e2209652e86,aea33262-0922-a475-1fa4-e9fc65313891,0b3159e5-7c83-a6c3-8e0e-4a35d27c7250

 

Now, I would like to execute

 

xe vbd-destroy on each of the uuids.

 

Can I combine those two into one command?

Please help, I am a total  noob when it comes to linux scripting and the first command was all I could do by myself.

 

Thank you :-)

Link to comment

8 answers to this question

Recommended Posts

1 hour ago, Tobias Kreidl said:

Something like this should work:

 

#!/bin/bash

list=`xe vbd-list vdi-uuid=$(xe vdi-list other-config=ctxs-pool-backup:\ true params=uuid --minimal) params=uuid --minimal`

for item in $list; do

  echo "Now destroying VBD $item ..."

  xe vbd-destroy uuid=$item

done

 

Thank you, but... no... it doesn't work... I have corrected the syntax and removed the vbd-destroy for safety. But it still does not work the way it should. It seems that the formating of the uuid list is not correct...

 

list=$(xe vbd-list vdi-uuid=$(xe vdi-list other-config=ctxs-pool-backup:\ true params=uuid --minimal) params=uuid --minimal)
for item in $list; do
  echo "Now destroying VBD $item ..."
done
 

 

 

Link to comment

I mised the VDI dependency to weed out the VDBs, sorry; you might try something like this (and don't forget the back ticks!):

 

vdilist=`xe vdi-list other-config=ctxs-pool-backup:true params=uuid --minimal`

for vditoken in $vdilist; do

   vdbitem=`xe vbd-list vdi-uuid=$vditoken --minimal

   echo "Now destroying VBD $vdbitem ..."

   xe vbd-destroy uuid=$vdbitem

done

 

-=Tobias

Link to comment
11 hours ago, Tobias Kreidl said:

I mised the VDI dependency to weed out the VDBs, sorry; you might try something like this (and don't forget the back ticks!):

 

vdilist=`xe vdi-list other-config=ctxs-pool-backup:true params=uuid --minimal`

for vditoken in $vdilist; do

   vdbitem=`xe vbd-list vdi-uuid=$vditoken --minimal

   echo "Now destroying VBD $vdbitem ..."

   xe vbd-destroy uuid=$vdbitem

done

 

-=Tobias

 

Thank you Tobias, but the results are still the same :-(

As you can see below it is processing the whole list of uuids as one parameter.
I have corrected the syntax of your script a bit.


[server]# vdilist=$(xe vdi-list other-config=ctxs-pool-backup:\ true params=uuid --minimal)
[server]# for vditoken in $vdilist; do
>    vbditem=$(xe vbd-list vdi-uuid=$vditoken --minimal)
>    echo "Now destroying VBD $vbditem ..."
> done
Now destroying VBD 01a2aa7f-f0dd-75b5-7cb3-9c5c2a801877,6e1cab4a-d7d7-b141-e16d-7786dd51063c,89461690-5be8-117b-620d-f14482273054,d43c87c0-7c78-6ef0-ea51-2f08eb0d675e,db4f6456-c059-99d7-c797-49bad583faea,062cc4fb-cee0-5fc0-6255-88764aae5707,7e64119a-7169-efef-88e1-5efc7033606b,287dc05c-f0fc-e3f0-dd89-30e316cadea3,4b5ff655-d938-a7a1-da5a-0ad9e7b5b477,70e17ebd-b8db-3557-20b7-6b8c43b85c56,63928e76-f650-e3de-bed2-ba94dac2de5a,cc3cada7-e5b6-c433-7125-6c7661e61478,520d1844-316d-fbf1-45e2-7e2209652e86,aea33262-0922-a475-1fa4-e9fc65313891,0b3159e5-7c83-a6c3-8e0e-4a35d27c7250 ...

 

Link to comment

I forgot the inner loop...

 

vdilist=`xe vdi-list other-config=ctxs-pool-backup:true params=uuid --minimal`

for vditoken in $vdilist; do

      vdbitem=`xe vbd-list vdi-uuid=$vditoken --minimal

      for vdb in $vdbterm; do

         echo "Now destroying VBD $vdb ..."

         xe vbd-destroy uuid=$vdb

      done

done

 

 

I probably still have it looping too much -- might need a "break" after the first "done" or it'll

Link to comment

Well, your script is not working...

The best I came up with is a command that outputs vbd-destrou commands to execute:

 

xe vbd-list vdi-uuid=$(xe vdi-list other-config=ctxs-pool-backup:\ true params=uuid --minimal) params=uuid --minimal | sed 's/,/\n/g' | sed 's/^/xe vbd-destroy uuid=/'


 

But I am not able to automate this completely.

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...