Need shell script to Telnet multiple node , Ping some IP and print output

Hi Team,
Need shell script to Telnet multiple node , Ping some IP and print output like pass or fail.
Need this script to check reachability of multiple nodes at same time.
Help me.

I use this but not working...
Eg.
in this script i need to telnet 5601:200:370:111::91 and ping 5601:200:13f:1d0:3:2:103:02 ip

IP_TABLES.txt

5601:200:370:111::91 5601:200:13f:1d0:3:2:103:02
5601:200:370:111::91 5601:200:11d:c00:3:2:103:52
5601:200:370:111::91 5601:200:11e:100:3:2:103:e1
5601:200:370:111::91 5601:200:11d:500:3:2:103:145
5601:200:370:112::71 5601:200:11d:500:3:2:103:c8
5601:200:370:112::71 5601:200:12d:500:3:2:103:47

Ping.sh

#!/bin/bash
 
pingcnt='10'
iptable_file="IP_TABLES.txt"
PASSWD="********"
SUBNODE_DIR=/home/nodeuser
ERROR="Transfer"



cat /home/lotus/bin/cmd/$iptable_file | while read IP
                                do
                                                echo $IP > temp.txt
                                                MAINNODE_IP=`awk '{print $1}' temp.txt`
                                                SUBNODE_IP=`awk '{print $2}' temp.txt`
                                               
                                                ping6 -c 10 $SUBNODE_IP > ping_$SUBNODE_IP.log &
                                done
 
                                echo ""
                                echo "**** WAIT until ping test end ****"
                                echo ""
 
                                sleep 10
 
                                echo"" >> result_ping.log
                                date >> result_ping.log
                                sleep 5
                                echo "--------- SUBNODE IP ---------" >> result_ping.log
 
                                cat /home/lotus/bin/cmd/$iptable_file | while read IP
                                do
                                                echo $IP > temp.txt
                                                SUBNODE_IP=`awk '{print $2}' temp.txt`
                                                cat ping_$SUBNODE_IP.log | grep transmitted > temp_$SUBNODE_IP.log
                                                data=`awk -F ',' '{print $3}' temp_$SUBNODE_IP.log`
                                                if [ -s temp_$SUBNODE_IP.log ]
                                                then
                                                                echo "$SUBNODE_IP  : $data" >> result_ping.log
                                                else
                                                                echo "$SUBNODE_IP  : 100% packet loss" >> result_ping.log
                                                fi
                                done
                                rm -rf ping_*
                                rm -rf temp*
                                sleep 10
                                cat  /home/lotus/bin/cmd/result_ping.log
                               
                               
                ;;
esac

output

unknown host
unknown host
unknown host
unknown host
unknown host
 
**** WAIT until ping test end ****
 
unknown host
 
Sat May  9 20:14:04 IST 2015
--------- SUBNODE IP ---------
 
Sat May  9 20:16:39 IST 2015
--------- SUBNODE IP ---------
5601:200: 100% packet loss126
5601:200: 100% packet lossa
5601:200: 100% packet loss2
5601:200: 100% packet loss8a
5601:200: 100% packet lossa
5601:200: 100% packet loss6

---------- Post updated 05-10-15 at 12:52 AM ---------- Previous update was 05-09-15 at 08:26 AM ----------

Hi Team,
Please help me....

Good morning:

I'd start by changing the main loop, first and last line:
To:

while read tIP pIP
...
done</home/lotus/bin/cmd/$iptable_fil

So it now reads the the first value for 't'elnet-ip, and the second value for 'p'ing-ip.

Why are you reading the whole line in 2 loops, in- and outside?
Makes it much more complex and slower thant it would be.

Are you sure you even need the 'telnet' ips?
You set the mainnode, bu never use it (or i overseen it).

From one of my scripts:

ping -c1 $URL | grep -e trans -e ms

You could chagne to like:

ping -c1 $pIP | grep -e trans -e ms && \
     echo "$pIP  : $data" >> result_ping.log || \
     echo "$pIP  : 100% packet loss" >> result_ping.log

Basicly, the 2 examples should be enough.
-- though, the $data is now unset (empty).

hth

1 Like

Thanks But i m very new to shell scripting ....can u plz post me entire code after change..plz

For a new one, you writing quite complex scripts :stuck_out_tongue:
Anyway, just writing the basics, try (untested):

while read tIP pIP
    ping6 -c1 $pIP | grep -e trans -e ms && \
         echo "$pIP  : Found" >> result_ping.log || \
         echo "$pIP  : 100% packet loss" >> result_ping.log
done</home/lotus/bin/cmd/$iptable_fil

hth

1 Like

Thanks..
This is not my script ..i m just try to run it