首页 > 其他 > 详细

自定义监控脚本--监控端口

时间:2019-06-14 13:08:42      阅读:183      评论:0      收藏:0      [点我收藏+]
#!/bin/bash

port_array=(`netstat -ntpl|egrep -i "$1"|awk {print $4}|awk -F: {if ($NF~/^[0-9]*$/) print $NF}|sort|uniq`)
length=${#port_array[@]}

printf "{\n"
printf \t‘"\"data\":["
for ((i=0; i<$length; i++))
do
    printf \n\t\t{
    printf "\"{#TCP_PORT}\":\"${port_array[$i]}\""
    if [ $i -lt $[$length - 1] ]; then
        printf ,
    fi
done

printf "\n\t]\n"
printf "}\n"

输出

[root@localhost alterscripts]# ./discovery_port.sh   
{
        "data":[
                {"{#TCP_PORT}":"10050",
                {"{#TCP_PORT}":"2371",
                {"{#TCP_PORT}":"25",
                {"{#TCP_PORT}":"3306"
        ]
}

 

自定义监控脚本--监控端口

原文:https://www.cnblogs.com/dingzp/p/11022485.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!