shell脚本检查端口是否占用(简单型)
时间:2015-01-14 12:49 来源:linux.it.net.cn 作者:IT
用linux shell脚本检测端口是否被占用,当某一端口被linux下进程占用时,可以尝试用此脚本检测下端口的占用状态。
shell脚本检测端口占用:
#!/bin/bash
#
port=$1
echo "check $port"
grep_port=`netstat -tlpn | grep "\b$port\b"`
echo "grep port is $grep_port"
if [ -n "$grep_port" ]
then
echo "port $port is in use"
exit 1
else
echo "port is not in use"
fi
(责任编辑:IT)
用linux shell脚本检测端口是否被占用,当某一端口被linux下进程占用时,可以尝试用此脚本检测下端口的占用状态。
shell脚本检测端口占用:
#!/bin/bash
# port=$1 echo "check $port" grep_port=`netstat -tlpn | grep "\b$port\b"` echo "grep port is $grep_port" if [ -n "$grep_port" ] then echo "port $port is in use" exit 1 else echo "port is not in use" fi (责任编辑:IT) |