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
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. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 253 bytes Desc: OpenPGP digital signature URL: <http://lists.centos.org/pipermail/centos/attachments/20110503/961bffa9/attachment.sig>
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 at centos.org> To: "CentOS mailing list" <centos at 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 at centos.org http://lists.centos.org/mailman/listinfo/centos
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! > timLast 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