List the IP address of list of servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List the IP address of list of servers
# 1  
Old 05-20-2014
Linux List the IP address of list of servers

Hi

I have a file containing server names and i can ssh to all these servers without password.

Could any body suggest me how to list out IP address of all the servers?

Now i am manually doing this, like ssh to each server and run "ifcong -a" command and copy the ipaddress to a excel sheet.

can anybody advice a shell script to get servername and ipaddress side by side?

example output
Code:
server1    x.x.x.x
server2    x.x.x.x
server3    x.x.x.x
server4    x.x.x.x
-
-
-

like above....

Thanks
siva
# 2  
Old 05-20-2014
Code:
man nslookup

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 05-20-2014
So you have list of hostname?
Try something like

Code:
while read SERVER
do
 ssh -q $SERVER "$COMMAND" | <further processing of the output if required> >> output.txt
done < hostname.lst

If you have specific usernames you want to login to, add them to hostname.lst
Code:
user1 server1
user2 server2

And use it like,

Code:
while read USERNAME SERVER
do
 ssh -q ${USERNAME}@$SERVER "$COMMAND" | <further processing of the output if required> >> output.txt
done < hostname.lst

# 4  
Old 05-20-2014
Code:
for SERVER in `cat server-list`
do
ping -c 1 $SERVER | awk '{ print $2"\t"$3 }' | head -n 1 | tr -d '()'
done


Last edited by akitafan; 05-20-2014 at 11:20 PM.. Reason: Update code
# 5  
Old 05-20-2014
Since the host names are resolving already for ssh, there is no need to remotely connect or ping the systems (that will only disclose currently alive servers, at best).
A query with nslookup as mentioned in post #2 or with dig, would be sufficient.

Here's an example using dig
Place all the server names in hostsfile.txt

Code:
dig -f hostsfile.txt +noall +answer | awk '{print $1, $NF}'

This User Gave Thanks to Aia For This Post:
# 6  
Old 05-21-2014
Try the following:-
  • man host
  • man ping
  • man nslookup
  • view /etc/hosts

If using the hostname gets you connected, why do you need the IP address? I'd always steer people away from these as if the network requires changes (physical move, company merger etc.) you don't want to have to recode it all over the place if a DNS server can be a central reference where a single change will implement for all.


Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Traverse through list of servers using ssh non-interactively.

I have 300 servers listed in servers.txt I motto is to check if my id "user1" has sudo privileges on the 3000 servers. I m using sudo -l to check if I have privileges or not. If wish to check this either non-interactively; if not; interactively. Below is the script I wrote: ... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. UNIX for Dummies Questions & Answers

IP address list padding with 0

Hi All, I'm hoping one of you helpful lot could come up with a way I can do the below. I've been trying to think how is best but have struggled to come up with a way. I have a list of IP addresses in the below format 1.1.1.1 102.1.2.3 102.102.1.10 102.102.102.1 I need to compare... (4 Replies)
Discussion started by: mutley2202
4 Replies

3. Shell Programming and Scripting

Ping script to list of servers

Hi Friends, I have experience in redhat/ Ubuntu OS, but I am very new to solaries os. my servers OS is Oracle Solaris 10 8/11 s10x_u10wos_17b X86. I have a file contains 200 servers IPs one by one. now I want a script to chaeck which IPs are pinging, not pingning. I... (8 Replies)
Discussion started by: kumar85shiv
8 Replies

4. Shell Programming and Scripting

List of servers that are NOT authorized for password-less SSH

Hello friends, We have around 500 servers (HPUX, AIX and linux) and all of them need to be accessed from our management box (linux) via password-less ssh. Out of 500 around 150 servers are setup password-less. We need to setup password-less SSH for remaining servers. First we need to get the... (3 Replies)
Discussion started by: magnus29
3 Replies

5. Solaris

Servers lacked maintenance, here's my to-do list

I'll be taking over administration of a rack of Solaris machines that haven't had an admin for the last 9 months. Prior to that they had limited maintenance. I understand there are a few tickets that will need addressed, but I won't have the details for a few days on them. Regardless, I'm trying to... (6 Replies)
Discussion started by: DustinT
6 Replies

6. Shell Programming and Scripting

List and Compare Files accross different servers.

Hi all, This is my situation. First thing is I cannot use rsync to accomplish this. I don't have on my systems and we can't put it on. I run HP-UX 11v3. I have a list of files generated every day which tells me which files are not in sync with the rest of the servers.I want to ls -l the... (1 Reply)
Discussion started by: zixzix01
1 Replies

7. UNIX for Dummies Questions & Answers

Find unique IP address in a list

Hello, I got a list of IP address from which I would like to remove the duplicates. I cat the file and pipe it to uniq -u or uniq -c, I got the same output with all the duplicates. Can anybody please tell me how I can remove the duplicates IPs from this file? This is what I used. cat filename |... (3 Replies)
Discussion started by: Pouchie1
3 Replies

8. Shell Programming and Scripting

ksh - how to list all ip address between 2 ip address

Trying to do a ksh script that needs to list all ip address between ip address a and b .. ie. Ip address A=192.168.1.200 Ip address B=192.168.2.15 So the subnet changes from 1 to 2 but I want to list all possible ip addresses between the 2.. Which would be: 192.168.1.200... (4 Replies)
Discussion started by: frustrated1
4 Replies

9. UNIX for Dummies Questions & Answers

send email from address list and subject list

Hello, Here is my problem. there are two files. first.txt <<< contains email address ====== abc@mail.com abd@mail.com abe@mail.com second.txt <<< contains webpage links ======== http//www.test.com/abc/index.html http://www.test.com/abd/index.html http://www.test.com/abe/index.html... (2 Replies)
Discussion started by: paulds
2 Replies

10. UNIX for Advanced & Expert Users

want to mail a list of files in different servers

Hi All, I am running my script in crontab and it is generating a file everyday. And I have 10 different servers and i am running the same script in every server in crontab which generates a file in every server per day. I want to retrieve those files from each server everyday. I want to... (1 Reply)
Discussion started by: AshishK
1 Replies
Login or Register to Ask a Question