The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.


Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 20
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Question relate to AWK

Hi,

I would like to setup a FOR loop script to find out all the existing linux workstation in the network w/ ip address, hostname and linux version.

I created a basic FOR loop script:

for i in $(seq 1 254)
do
echo 10.72.169.$i >> result
ssh -o ConnectTimeout=3 root@10.72.169.$i "hostname" >> result
ssh -o ConnectTimeout=3 root@10.72.169.$i "cat /etc/redhat-release" >> result
done


However, the output is like this:

.
.
10.72.169.21
lumines.devo.ilx.com
Fedora Core release 5 (Bordeaux)
10.72.169.22
10.72.169.23
10.72.169.24
copper.devo.ilx.com
10.72.169.25
frogger.devo.ilx.com
Fedora Core release 5 (Bordeaux)
10.72.169.26
afterlife.devo.ilx.com
Red Hat Linux release 9 (Shrike)
10.72.169.27
10.72.169.28
molybdenum
Red Hat Linux release 9 (Shrike)
10.72.169.29
Red Hat Linux release 7.2 (Enigma)
10.72.169.30
.
.
.

I want the output to be like :

10.72.169.21 lumines.devo.ilx.com Fedora Core release 5 (Bordeaux)
10.72.169.22 abc.devo.ilx.com Fedora Core release 5 (Bordeaux)
.
.

I think with the command AWK, i can do that. But I don't know how to make it to work. Can someone show it to me?

Thanks
BEELOO
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,203
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Code:
for i in $(seq 1 254)
do
    echo 10.72.169.$i `ssh -o ConnectTimeout=3 root@10.72.169.$i "hostname; cat /etc/redhat-release"
done >>result
Reply With Quote
  #3 (permalink)  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 20
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Sorry, it doesn't work. it said:

test2: line 3: unexpected EOF while looking for matching `''
test2: line 5: syntax error: unexpected end of file
Reply With Quote
  #4 (permalink)  
Old 04-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,203
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Yeah, sorry, I left that off, you need one more backquote at the very end of the long line.
Reply With Quote
  #5 (permalink)  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 173
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
First of all it's bad practice to allow root logins via ssh. You have been warned ...

There's a backtick (`) missing at the end of the echo line.

(a better looking option would be the following inside the loop (no redirection at the end of the loop then)

echo -n 10.72.169.$i >> result
ssh -o ConnectTimeout=3 root@10.72.169.$i "hostname; cat /etc/redhat-release" >> result
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB 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 -7. The time now is 10:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102