I have prepared script which will check for listening message for ports 1199,1200 and 1201. I need modifcation in script in such a way that if port 1200 is not listening then it should message rmi port 1200 is not listening. Smap for port 1199 and 1201.
kindly guide me to acheive this solution
#!/usr/bin/ksh
status=`netstat -na | grep 1200 | grep -i listen |sed -n '1p'| awk {'print $7'}`
status1=`netstat -na | grep 1201 | grep -i listen |sed -n '1p'| awk {'print $7'}`
status2=`netstat -na | grep 1199 | grep -i listen |sed -n '1p'| awk {'print $7'}`
for s1 in $status $status1 $status2
if [ $s1 = "LISTEN" ];
then
echo "RMi Server is running fine on server `hostname` @ `date`"
else
echo "RMI Server is not running fine on server `hostname` @`date`" >>/opt/app/rmiserver.txt
fi
netstat -na| grep 5152 | grep -i listen >/dev/null
status1=`echo $?`
netstat -na | grep 1200 | grep -i listen >/dev/null
status2=`echo $?`
for status in $status1 $status2
do
if [ $status -eq 0 ];then
echo "listening"
else
echo "not listening"
fi
done
Your own code needs following changes:
for s1 in $status $status1 $status2
do
if [ $s1 = "LISTEN" ];then
echo "RMi Server is running fine on server `hostname` @ `date`"
else
echo "RMI Server is not running fine on server `hostname` @`date`" >>/opt/app/rmiserver.txt
fi
done
Thanks for the response. Actually my script is also working fine. I need only modifcation in such a way that if any of the port out of 1200,1201 or 1199 is not listening then it should log messages in file such "rmi port 1200 or 1201 or 1199 is not listening".
---------- Post updated at 04:35 AM ---------- Previous update was at 04:32 AM ----------
Hello Franklin,
I am not getting any error messages. I need only one modifcation in script while checking variable value if any of the varible value ie. status or status1 or status is not matching then it should log messages saying that port 1200 ot port 1199 or port 1201 is not listening while check it;s corresponding variables.