LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-06-2010, 09:20 PM   #1
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 122

Rep: Reputation: 15
Post 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...

Last edited by bluethundr; 10-06-2010 at 09:23 PM.
 
Old 10-06-2010, 09:56 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
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
 
Old 10-06-2010, 10:47 PM   #3
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 122

Original Poster
Rep: Reputation: 15
Thumbs up 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!!
 
Old 10-06-2010, 11:54 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Heh ... anytime ;}


Cheers,
Tink
 
Old 10-07-2010, 04:05 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,562

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
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
 
  


Reply

Tags
bash scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 8 04-05-2011 09:18 AM
for loop or while loop to read the fields of a file.. visitnag Linux - Newbie 10 09-02-2010 08:47 PM
C State not entered Libra Linux - Laptop and Netbook 0 11-18-2008 08:02 AM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration