centos下shell网络监控脚本
以下是一个基本的CentOS下的Shell网络监控脚本的示例:
#!/bin/bash
# 定义监控的目标IP地址和端口号
target_ip="192.168.0.1"
target_port="80"
# 定义监控时间间隔(秒)
monitor_interval=10
# 定义监控超时时间(秒)
monitor_timeout=5
while true; do
# 使用nc命令进行连接测试
nc -z -w $monitor_timeout $target_ip $target_port
# 检查nc命令的退出状态
if [ $? -eq 0 ]; then
echo "$(date): 连接成功"
else
echo "$(date): 连接失败"
fi
# 等待一段时间后再次进行监控
sleep $monitor_interval
done
请注意,这只是一个非常基本的示例脚本,仅用于演示如何使用Shell脚本进行网络监控。根据实际需求,您可能需要添加更多的功能和错误处理
原文地址: https://www.cveoy.top/t/topic/hWWr 著作权归作者所有。请勿转载和采集!