![]() |
|
|
|||||||
| 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. |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|||
| Google UNIX.COM |