I would like to find a Linux command that I could write a bash to test the communication between three (or more servers).
My need is showed in the scenario below:
Source Gateway Dest Host A Host B1 Host C1 Host A Host B2 Host C2 Host A Host B3 Host C3
I have a host A that is going to have a bash to test the communication from host B1 to C1, C2 and C3, than the communication from host B2 to to C1, C2 and C3 and so on.
This test could be a single ping or traceroute what I have tried without success so far.
Answer
Not sure whether it is the most elegant solution, but you could simply place a “checkconnections.sh” on each of your B1 to Bx, which runs pings to the respective other servers and checks if the result is 0% package loss or not:
ping -c 3 192.168.0.34 | grep " 0.0% packet loss"
Note: different systems appear to print the ping results in different formats, so double check that grep ” 0.0% packet loss” actually catches your system’s output!
If the result is empty, your connection failed. If it isn’t, the connection should be ok. Tell the script to write an output/log file.
You can then put a statuscollection.sh on your Host A, which loops through all the boxes B1 to Bx, executes the check-scripts there and collects the log files afterwards.
ssh user@boxBx 'path/to/checkconnections.sh'
scp user@boxBx:path/to/log.file destination/Bxlog.file
For this to work you’ll need to set up key based authentication (http://www.cyberciti.biz/tips/ssh-public-key-based-authentication-how-to.html).
Hope that makes sense.
Edit:
Depending on key based authentication (see above) and you knowing the IP addresses of all the Boxes (B1 to Bx) and Hosts (C1 to Cx), the following may work:
#!/bin/bash
echo "Beginning connection tests."
# create / clear log file
echo "" > results.log
for boxip in [list IPs of your boxes B1 to Bx here]
do
for hostip [list IPs of your hosts C1 to C2 here]
do
echo "Checking connection from $boxip to $hostip:" >> results.log
ssh user1@b$boxip 'ping -c 3 $hostip | grep " 0% packet loss"' >> results.log
echo "--------------------------------" >> results.log
done
done
For more info on loops see example 11-1 here: http://tldp.org/LDP/abs/html/loops1.html
Attribution
Source : Link , Question Author : Emerson Soares , Answer Author : JoW