[CentOS] virtdown script

Tue May 3 19:09:03 UTC 2011
aurfalien at gmail.com <aurfalien at gmail.com>

On May 3, 2011, at 11:55 AM, Ljubomir Ljubojevic wrote:

> Tim Dunphy wrote:
>> hello list!
>>
>> I have a small shell script that I wrote that is meant to quickly  
>> bring down all of my xen instances in a quick and easy manner. Odd  
>> thing is, it does work on the command line. But if I put it into a  
>> script this happens:
>>
>>
>> [root at LCENT03:/home/bluethundr/bin] #virtdown
>>
>> it expects another command to happen. which is odd since all of the  
>> text delimiters (" and ') are balanced according to vim. I was  
>> wondering if I could have an opinion on why this might be  
>> happening. Here's the script:
>>
>>
>>
>> #/bin/bash
>>
>> for i in $(virsh list | grep -v -e Id -e --- -e Domain-0 | awk  
>> '{print $1}');
>> do
>> /usr/bin/virsh shutdown $i
>> done
>>
>>
>> thanks in advance!
>> tim
>
> Last thing I saw is "#/bin/bash" instead of "#!/bin/bash". Fix and  
> try.
>
> The rest of suggestions:
> Add plenty of unique "echo" lines so you can see where it brakes.
>
> Also try $(`virsh list | grep -v -e Id -e --- -e Domain-0 | awk  
> '{print
> $1}'`)
>
> and try sending that same part to variable first and echo the variable
> so you can see output.
>
>
> #!/bin/bash
>
> list=$(virsh list | grep -v -e Id -e --- -e Domain-0 | awk '{print  
> $1}')
> echo "the list is=$list"; sleep 2
> for i in "$list";
> do
>    echo "Running shutdown for item $i"; sleep 2
>    /usr/bin/virsh shutdown $i
>    echo " shutdown for item $i is complete"; sleep 2
> done
>
> and try version with:
> list=$(`virsh list | grep -v -e Id -e --- -e Domain-0 | awk '{print  
> $1}'`)
>
> Ljubomir

Does this work for HVMs?

- aurf