autoDeploy/checkPort.sh
2024-02-06 11:30:31 +08:00

42 lines
726 B
Bash
Executable File

#!/bin/bash
function checkPort()
{
ip_address=$1
port=$2
# 使用nc命令检测连接
nc -zv -w 2 $ip_address $port
# 检查nc命令的退出状态
if [ $? -eq 0 ]; then
result=true
else
result=false
fi
# 将结果赋值给变量
is_active=$result
# 打印最终结果
# 根据连接状态输出不同的提示
if [ "$is_active" = true ]; then
echo 1
else
echo 0
fi
}
res=$(checkPort $1 $2)
if [ "$res" -eq 1 ]; then
echo "service on $1 $2 worked normally"
else
echo "service port:"$2 " is not actived, try to restart it"
#mysql -uroot -pAbcd@1234 -h0.0.0.0 -e "SET GLOBAL lower_case_table_names = 1;"
# systemctl restart shadowsocks-libev-server@libev
eval $3
fi
exit