LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Hwaddr of all nodes on a cluster (http://www.linuxquestions.org/questions/linux-server-73/hwaddr-of-all-nodes-on-a-cluster-754062/)

usagi32 09-10-2009 01:56 AM

Hwaddr of all nodes on a cluster
 
Hi,

I need to create a list of all the hostnames and their HWaddr (hardware addresses [also called MAC address]) for all the nodes on my Linux cluster.

I know that all the hostnames can be found in /etc/hosts, but there doesn't seem to be a list of HWaddr numbers.

I guess one can write a script to ssh into all the hostnames found in /etc/hosts and execute the command

/sbin/ifconfig | grep 'HWaddr'

on each node and concatenate this into a single text file. My Linux skills are not good enough to do this though.

Does anyone know if there is a list of HWaddr numbers in system directory, or alternatively, does someone know how to write a script to generate the HWaddr lists?

Thanks,
Bryan

colucix 09-10-2009 03:52 AM

You may want to do a simple loop over the cluster nodes and run the ifconfig command through ssh. Are the IP address of the nodes in numeric sequence (for example in a interval between 192.168.0.10 and 192.168.0.25)? Or have you a list of the IP addresses stored in a file? Are the machines set up for passwordless login?

If these conditions are met, you can try something like:
Code:

#!/bin/bash
while read ip
do
  mac=$(ssh -n user@$ip "/sbin/ifconfig | awk '/HWaddr/{print \$NF}'")
  printf "%s\t%s\n" $ip $mac
done < file_with_ips_one_per_line


usagi32 09-10-2009 11:21 AM

Thanks for the help colucix!

I have a list of the IP addresses stored in a file. Suppose I have each of them listed on a separate line in a text file called "ip_addresses.txt". How would the above code look like using this text file?

Thanks
Bryan

colucix 09-10-2009 03:11 PM

Exactly as it is. Just substitute my dummy file name "file_with_ips_one_per_line" with the actual "ip_addresses.txt" (without quotes). Also substitute "user" with a real username for which you have set-up passwordless access for all the cluster nodes.

usagi32 09-11-2009 12:21 AM

Thanks colucix! You're the man!


All times are GMT -5. The time now is 10:47 PM.