批量检测端口连通性

2019-12-25  本文已影响0人  繁华丶凋零

主脚本check.sh:

#!/bin/bash
echo "" > status

source_ip=($1)
target_ip=($2)
target_port=($3)
for ip_source in `echo ${source_ip[*]}` 
   do   
      for ip_target in `echo -e ${target_ip[*]}` 
         do
            
            for port_target in   `echo -e ${target_port[*]}`
                do
                    ssh support@${ip_source}  -n  "nc -n -w 1 ${ip_target}  ${port_target} >/dev/null 2>&1 && echo ${ip_source} connect ${ip_target} ${port_target} ok || echo ${ip_source} connect ${ip_target} ${port_target} failed "  >> status

             done
    done
done

cat status   

这里是配合jenkins 用的, jenkins配置如下:


图片.png

jenkins job的 Excuse shell 内容如下:


cd /home/jenkins/port_check ;

#source_ip=`echo -e $source_ip| sed 's/ /\n/g'` ;
#target_ip=`echo -e $target_ip| sed 's/ /\n/g'` ;
#target_port=`echo -e $target_port| sed 's/ /\n/g'` ;

bash  check.sh  "$source_ip"   "$target_ip"  "$target_port"

jenkins的参数配置如下格式:


图片.png
上一篇下一篇

猜你喜欢

热点阅读