Hi,
I want to create a script that will check the connectivity to a IP address & port using nc command & if there is a connectivity issue, it will send a SMS alert.
I have written a basic script which has IP address & port hard coded in it & it is working fine.
I want to read IP address & port from a text file so that every half an hour the script checks connectivity to multiple IP addresses & ports.
I also want to put the IP address & port in the SMS text that will be sent as alert in case of no connectivity.
Below is my script.
Please help me to know how I can read one by one <Server IP> & <Port> from the following text file format (File name is input.txt) & use it in above script.
input.txt
######
In the above text file, Server IP & Port are separated by a <TAB>.
Thanks,
Sunil
I want to create a script that will check the connectivity to a IP address & port using nc command & if there is a connectivity issue, it will send a SMS alert.
I have written a basic script which has IP address & port hard coded in it & it is working fine.
I want to read IP address & port from a text file so that every half an hour the script checks connectivity to multiple IP addresses & ports.
I also want to put the IP address & port in the SMS text that will be sent as alert in case of no connectivity.
Below is my script.
Code:
#!/bin/bash
cd /rovp_test/
nc -zv <Server IP> <Port> 2> /rovp_test/logfile2
if /usr/xpg4/bin/grep -q open logfile2; then
echo port opened
elif /usr/xpg4/bin/grep -q refused logfile2; then
echo connection refused
wget "http://xxx.xxx.xxx.xxx:8077/sendsms?...ect+to+<Server IP>:<Port>"
else
echo unknown result
fi
input.txt
######
Code:
10.239.198.1 8080
10.239.94.1 80
10.239.198.50 6666
10.239.94.224 4848
Thanks,
Sunil