BASH SHELL下两个用于检查端口情况的脚本
#!/bin/bashdeclare -a CHK_TCP_CMD=`netstat -tln|egrep 0.0.0.0|awk '{print $4}'|awk -F: '{print $2}'|sort -n`
declare -a PORT_NO_EXISTS
declare -i CURRENT_PORT=0
for TCP_PORT in $@
do
#IS NUMBER
expr "$TCP_PORT" + 0 >/dev/null 2>&1
if [ "$?" != "0" ];then
echo "$TCP_PORT not a number."
exit 1
fi
PORT_NO_EXISTS[$CURRENT_PORT]=$TCP_PORT
for LSN_PORT in $CHK_TCP_CMD
do
if [ $TCP_PORT == $LSN_PORT ];then
unset PORT_NO_EXISTS[$CURRENT_PORT]
break
fi
done
((CURRENT_PORT++))
done
if [ ${#PORT_NO_EXISTS[@]} -gt 0 ];then
echo "TCP ports ${PORT_NO_EXISTS[@]} failed."
exit 1
fi
exit 0
页:
[1]