1 钉钉提示信息
业务告警
主机ip:x.x.x.x
主机名称:test
端口:2001 port is not running
服务名称:ability-sms-core
2 思路准备
获取本地tcp所有端口
port1=netstat -an|grep LISTEN|egrep "0.0.0.0|:::"|awk '/^tcp/ {print $4}'|awk -F: '{print $2}'|sort -n
获取pid和进程名
lsof -n -i:9001|grep TCP|grep LISTEN|grep IPv4|awk '{printf("%d\t%s\n"),$2,$1}'
3 编写脚本
vim ports_check.sh
#!/bin/bash
#chkconfig:2345 81 91
#decription:ports_check autostart
declare -A PORTS_SERVICE
PORTS=(2001 22 6001 6002 6003 6004 6005 6006 6007 6008 6009 9001 9002 9003)
PORTS_SERVICE=([2001]="ability-sms-core" [22]="sshd" [6001]="biz-app-core" [6002]="biz-user-core" [6003]="biz-feed-core" [6004]="bm-pms" [6005]="bm-biz" [6006]="biz-im-core" [6007]