服务器 运维 linux编写脚本,用来监控程序是否掉线 - :$PORT &#34

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多帮助力 👁️ 404 次阅读

新建一个文件,并给予权限:

touch port_monitor.sh 拼多多帮助力入口

chmod 777 port_monitor.sh

写入如下命令:

#!/bin/bash

# 定义要监控的端口号

PORT=3306

while true; do

# 使用netstat命令检查端口是否存在

netstat -tuln | grep ":$PORT "

if [ $? -ne 0 ]; then

echo " $(date) 端口 $PORT 不存在,执行命令..." >> ./port_monitor.log

else

echo "$(date) 端口 $PORT 存在" >> ./port_monitor.log

fi

# 等待1分钟

sleep 60

done

开启后台启动即可:

nohup ./port_monitor.sh &

注意:使用windows编写的文件是dos格式,需要转换成unix格式:

可以使用vim编辑器进行转换

set fileformat=unix

精彩文章

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧