How to get info about all the nodes in the network via SSH ?

Logic:

1. Checking if the host is alive.
2. Getting info about them, via remote commands.

Steps:

1. Prepare password free SSH access.
2. Make a simple script to get host info.

Prepare password free SSH access:
$ssh-copy-id user@host
or
cat ~/.ssh/id_dsa.pub | ssh user@remotehost 'cat >> ~/.ssh/authorized_keys

Make a simple script to get host info:

Step 1. Get the local ip say for eth0.
Step 2. Loop the range of ip and check if the host is alive.
Step 3. Use ssh to getinfo from /proc

Code

#!/bin/bash
user=root
getNodeinfo()
{
#Get the ip address for the range
ip=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' | cut -d"." -f1,2,3)
# ping test and list the hosts and echo the info 
for range in $ip ; do ping -c 1 -w 1 $ip > /dev/null 2> /dev/null >> /tmp/pinglog &&[ $? -eq 0 ] ; echo "Node $range is up" && echo "More info about the machine" ; echo "Kernel:$(ssh $user@$range cat /proc/version)" && echo "CPU info:$(ssh $user@$range cat /proc/cpuinfo )" && echo "Mem info:$(ssh $user@$range cat /proc/meminfo)" && echo "Release:$(ssh $user@$range lsb_release -a)" 
done
}

Got better method? Give your idea

Share this