#探测本机端口並执行脚本
#运行时,需要将端口作为参数
#需要安裝nmap-ncat .
#yum install nc -y;
#!/bin/bash
if [ ! -n "$1" ]
then
port=8080;
else
port=$1;
# 檢查本地8080端口是否已经被占用
nc -z localhost ${port};
# 如果端口不可用,則启动指定命令
if [ $? -eq 1 ]; then
echo "This port "${port}" does not exist.";
echo "Starting ...";
# 你要运行的命令,如 /opt/Tomcat/bin/startup.sh
/opt/Tomcat/bin/startup.sh;
else
echo "This port "${port}" already exists.";
fi