用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) |