![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | 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 |
|
#8
|
|||
|
|||
|
The outfile still very messy.
It looks like this: 10.72.169.110.72.169.210.72.169.310.72.169.410.72.169.510.72.169.610.72.169.710.72.169.810.72.169.91 0.72.169.1010.72.169.1110.72.169.1210.72.169.13datafeeds Red Hat Enterprise Linux AS release 3 (Taroon) 10.72.169.1410.72.169.1510.72.169.16xenon.devo.ilx.com Fedora Core release 5 (Bordeaux) 10.72.169.1710.72.169.1810.72.169.1910.72.169.2010.72.169.21lumines.devo.ilx.com Fedora Core release 5 (Bordeaux) 10.72.169.2210.72.169.2310.72.169.24 However, someone of ip address maybe dead or no one using it. Does it make any different? |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
I don't understand how you would get that output. Are you running the script exactly like I wrote it, just with an additional backquote after .../etc/redhat-release"?
|
|
#10
|
|||
|
|||
|
You could also put the IP address inside the ssh command; then you don't get any output from hosts which don't respond.
Code:
for i in $(seq 1 254)
do
ssh -o ConnectTimeout=3 root@10.72.169.$i "echo 10.72.169.$i `hostname` `cat /etc/redhat-release`"
done >result
|
|
#11
|
|||
|
|||
|
I want the host ip to show up even though the ip isn't being used or dead, so i used the below script and now it only turns all numbers in single line...
for i in $(seq 1 254) do echo -n 10.72.169.$i >> result2 ssh -o ConnectTimeout=3 root@10.72.169.$i "hostname; cat /etc/redhat-release'" >> result2 done RESULT: 10.72.169.110.72.169.210.72.169.310.72.169.410.72.169.510.72.169.610.72.169.710.72.169.810.72.169.91 0.72.169.1010.72.169.1110.72.169.1210.72.169.1310.72.169.1410.72.169.1510.72.169.1610.72.169.1710.72 .169.1810.72.169.1910.72.169.2010.72.169.2110.72.169.2210.72.169.2310.72.169.24 |
|
#12
|
||||
|
||||
|
Try variablizing the results:
Inside the loop: host=`echo 10.72.169.$i` server=`ssh -o ConnectTimeout=3 root@10.72.169.$i 'hostname'` release=`ssh -o ConnectTimeout=3 root@10.72.169.$i 'cat /etc/redhat-release'` then: echo "$host $server $release" >> result echo >> result Hope this helps. |
|
#13
|
|||
|
|||
|
Thanks.
How how can I put a title in the output file? For example: IP Address HOSTNAME VERSION 10.72.169.1 abc fedora 5 10.72.169.2 ded fedora 5 Thanks again. |
|
#14
|
||||
|
||||
|
You can use the '-e' switch with 'echo' and add tabs to line everything up:
echo -e "IP ADDRESS\t\tHOSTNAME\t\tRELEASE" >> result echo -e "10.x.x.x\t\thostname\t\trelease" >> result Hope this helps. |
||||
| Google The UNIX and Linux Forums |