The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
loop through variable finalight Shell Programming and Scripting 0 05-20-2008 11:30 PM
getting values from variable in a loop kriuz Shell Programming and Scripting 3 01-22-2008 05:50 PM
pass a variable to sed p in a loop? JohnMario Shell Programming and Scripting 7 01-02-2008 05:13 PM
Variable in While Loop Nested If geass Shell Programming and Scripting 6 03-26-2007 07:09 PM
variable not found with loop? douknownam Shell Programming and Scripting 2 09-27-2004 11:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-28-2006
sars sars is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 19
Lightbulb variable in a for loop[Resolved]

Hi...
i am trying to ping my servers .The hostnames are present in a file .They are separated by spaces in the file .
i am doing the following :


a=1
for name in $(cat host2 |cut -d" " -f$a)
do
echo Pinging server $name
ping -c5 $name
a=$a+1
done

It is working with the first name .But after that it stops.The for loop is not taking the next names .
Pls suggest .

Last edited by sars; 11-28-2006 at 05:59 AM..
  #2 (permalink)  
Old 11-28-2006
sars sars is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 19
one more change

I change my increment statement like this .

a=$(($a+1))

But still it is not working .
  #3 (permalink)  
Old 11-28-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
This ?


Code:
for name in $(< host2)
do
echo Pinging server $name
ping -c5 $name
done

  #4 (permalink)  
Old 11-28-2006
sars sars is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 19
it worked !!!

it worked ..thanks..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0