FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 05-03-2011, 05:54 PM
Tim Dunphy
 
Default virtdown script

hi and thanks for your reply.. either $1 or $2 seems to do it on the command line. virsh shutdown / xm shutdown takes both. I am simply trying to get this command to work in script form. thanks!

best!
tim

----- Original Message -----
From: "Johnny Hughes" <johnny@centos.org>
To: "CentOS mailing list" <centos@centos.org>
Sent: Tuesday, May 3, 2011 1:33:14 PM
Subject: Re: [CentOS] virtdown script

On 05/03/2011 09:39 AM, Tim Dunphy wrote:
> virsh list | grep -v -e Id -e --- -e Domain-0 | awk '{print $1}'

Do you want the "ID Number" or the "Name" to pass in? That gives you
the number, I think you want the name ... that would be $2 not $1.


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 06:44 PM
Kai Schaetzl
 
Default virtdown script

service xendomains stop ?

Kai


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 06:55 PM
Ljubomir Ljubojevic
 
Default virtdown script

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@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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 07:04 PM
 
Default virtdown script

Ljubomir Ljubojevic wrote:
> Tim Dunphy wrote:
>>
>> 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@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
>
> Last thing I saw is "#/bin/bash" instead of "#!/bin/bash". Fix and try.
<snip>
or (I'm guessing here, since I don't know what virsh list looks like)
awk '{if ( $0 !~ /Id/ && $0 ~ /Domain-0/ ) { cmd = "/usr/bin/virsh
shutdown " $1; system(cmd);}}' `virsh list`

mark "awk are us"

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 07:09 PM
 
Default virtdown script

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@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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 07:11 PM
Chris Geldenhuis
 
Default virtdown script

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@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
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
>
In cases like this it is also useful to put in a line "set -x" early on
in the script. It will then output every stage as it parses each command
allowing you to see where the resulys are not as expected.

ChrisG
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 09:05 PM
Ljubomir Ljubojevic
 
Default virtdown script

Chris Geldenhuis wrote:
> 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@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
>> _______________________________________________
>> CentOS mailing list
>> CentOS@centos.org
>> http://lists.centos.org/mailman/listinfo/centos
>>
>>
> In cases like this it is also useful to put in a line "set -x" early on
> in the script. It will then output every stage as it parses each command
> allowing you to see where the resulys are not as expected.
>
> ChrisG

Yes, you are right. I totally forgot about that. Another way is
"bash -x <script name>" to set it to debug mode without editing it.

Ljubomir
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 09:09 PM
Ljubomir Ljubojevic
 
Default virtdown script

aurfalien@gmail.com wrote:
> 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@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

Can not say. I use only one KVM gueat and virsh does not even work on my
server:

virsh: /usr/lib/libvirt.so.0: version `LIBVIRT_PRIVATE_0.6.1' not found
(required by virsh)

so my involvement is for now only because I am very good "bash"
programmer and willing to help.

Ljubomir
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-03-2011, 09:32 PM
Devin Reade
 
Default virtdown script

--On Tuesday, May 03, 2011 02:39:54 PM +0000 Tim Dunphy
<bluethundr@jokefire.com> wrote:

># /bin/bash

To start off, your hash-bang is missing its bang:

#! /bin/bash


Devin

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 07:42 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org