Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitoring IP add connected in Netstat grep ( SCRIPT)

Status
Not open for further replies.

aoroca

IS-IT--Management
Oct 3, 2003
39
CO


When I check NETSTAT I can see IP's connected to my Device by SMPP way, with status ESTABLISHED.

Is important for me check this IP and notify when someone of this IP change your status (different to ESTABLISH). I need :
check IP connections
report a log when IP is down or UP
execute a program file in order to send sms informig the issue.

Its possible have a file with IP address will be monitorig?, in order to dont change script and get a dynamic script.

Thanks a lot.

example: netstat | grep smpp -->

tcp4 0 0 smsbog.smpp 198.247.170.47.1272 ESTABLISHED
tcp4 0 0 smsbog.smpp 198.247.170.47.3996 ESTABLISHED
tcp4 0 0 smsbog.smpp 172.28.3.10.1564 ESTABLISHED
tcp4 0 0 smsbog.smpp 172.28.3.11.1095 ESTABLISHED
tcp4 0 0 smsbog.smpp 192.168.32.3.1142 ESTABLISHED
tcp4 0 0 smsbog.smpp 192.168.28.2.1613 ESTABLISHED
tcp4 0 0 smsbog.smpp 192.168.28.2.1611 ESTABLISHED
tcp4 0 0 smsbog.smpp 192.168.28.2.1612 ESTABLISHED
tcp4 0 0 smsbog.smpp 192.168.28.2.1610 TIME WAIT

for example, the script must check an report to me when last IP connection is failling because dont work properly with TIME WAIT status.


I have this script

$arriba = 1;
$date = `date`;
while( true ){
$ip_add=`cat ip_add.txt`;
$a=`netstat | grep smpp | grep $ip_add | grep ESTABLISHED `;
if($arriba == 1){
if(length($a) == 0 ) {
print "$date\t $ip_add ........... is DOWN \n";
execute some file
report a log file
$arriba =0;
}
}
if($arriba == 0){
if(length($a) > 0 ) {
print "$date\t $ip_add ........... is UP \n";
execute some file
report a log file
$arriba =1;
}
}
sleep 1;
}


How I can read IP add and put IP in order to review and send sms when this come down ? and vsa.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top