Good morning. I am trying to write a script that will tell me when a connection to a particuliar port number changes.
I have a server that connects to me on port 9010, if the connection dies it will try to reconnect to me again on port 9010 but it's port number will have changed. I want to know if the port number changes. I had written a script (tried to write a script) as follows, I don't know if the direction I am going would be the best, some advice would be appreciated.:
Pid_File="/home/user/stat_pid.txt"
PID=`netstat -an |grep 9010 | grep -v grep | awk ' { print $5 }'`
STAT_PID=`cat /home/user/stat_pid.txt`
###############################################################################
# Start Port checker
###############################################################################
if ( $STAT_PID ne $PID )
then
AdminMail=me@comp.com
echo "CONNECTION HAS DIED" > /tmp/txt.out
mail -s "Error Messages" $AdminMail < /tmp/txt.out
fi
I have a server that connects to me on port 9010, if the connection dies it will try to reconnect to me again on port 9010 but it's port number will have changed. I want to know if the port number changes. I had written a script (tried to write a script) as follows, I don't know if the direction I am going would be the best, some advice would be appreciated.:
Pid_File="/home/user/stat_pid.txt"
PID=`netstat -an |grep 9010 | grep -v grep | awk ' { print $5 }'`
STAT_PID=`cat /home/user/stat_pid.txt`
###############################################################################
# Start Port checker
###############################################################################
if ( $STAT_PID ne $PID )
then
AdminMail=me@comp.com
echo "CONNECTION HAS DIED" > /tmp/txt.out
mail -s "Error Messages" $AdminMail < /tmp/txt.out
fi