LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   why is this for loop not entered? (https://www.linuxquestions.org/questions/linux-newbie-8/why-is-this-for-loop-not-entered-836657/)

bluethundr 10-06-2010 09:20 PM

why is this for loop not entered?
 
hello linux q

I just wrote this script to shutdown my list of xen machines, back them up via rsync, then restart them. And can't for the life of me figure out why it never enters into the first (and likely other) for loop(s)

Code:


#!/bin/bash
VMLIST1='vm01 vm02 vm03 vm04 vm05 vm06 vm07 vm08 vm09'
VMLIST2='vm10 vm11 vm12 vm13 vm14 vm15'

for i in `/usr/bin/virsh list | /bin/grep -v -e Id -e --- -e 0 | /bin/awk '{print $1}'`; do /usr/bin/virsh shutdown $i; echo "shutting down session $i"; sleep 5; echo; echo; done

sleep 300

ssh sum2 "for i in `virsh list | /bin/grep -v -e Id -e --- -e 0 | /bin/awk '{print $1}'`; do virsh shutdown $i; echo "shutting down session $i"; sleep 5; echo; echo; done"

sleep 300

/usr/bin/rsync -avzp /mnt/store/xen/ /mnt/nas/xen/

sleep 300

for a in $VMLIST1; do /usr/sbin/xm create /mnt/store/xen/$a; echo "starting $a"; sleep 5; done



ssh sum2 "for a in $VMLIST2; do /usr/sbin/xm create /mnt/store/xen/$a; echo "starting $a; sleep 5; done"

I'd appreciate any suggestions you may have...

Tinkster 10-06-2010 09:56 PM

The first question will have to be what the output of
Code:

/usr/bin/virsh list | /bin/grep -v -e Id -e --- -e 0 | /bin/awk '{print $1}'
is :}



Cheers,
Tink

bluethundr 10-06-2010 10:47 PM

that did it!!!
 
ah! the output was nothing, tho I honestly thought I saw some output from the same line before.

this line did the trick!!

Code:

/usr/bin/virsh list | /bin/grep -v -e Id -e --- -e 'Domain-0' | /bin/awk '{print $1}'
so now that I am grepping for Domain-0 and not just 0 all is well..

thanks and best wishes!!

Tinkster 10-06-2010 11:54 PM

Heh ... anytime ;}


Cheers,
Tink

grail 10-07-2010 04:05 AM

Personally I would ask why the use of grep at all seeing awk would do all the work you have written.
Also a preference is to use $() at least when showing code here as very difficult for some of us oldies to pick up where the backticks start and stop :(


All times are GMT -5. The time now is 12:42 AM.