batch_telnet.sh(批量telnet)


本文总阅读量

#!/bin/bash
#ip和端口
ipaddress=$1
port=$2
#需要执行的次数
total=$3

if [ -z ${ipaddress} ] || [ -z ${port} ] || [ -z ${total} ];then
echo -e “请按正确格式数据参数:’sh batch_telnet.sh ip port 执行次数’”
exit
else
:
fi
countsuccess=0
countfail=0

for((i=1;i<=${total};i++))
do
echo “” |telnet ${ipaddress} ${port} > /tmp/telnet.log
numcount=cat /tmp/telnet.log |grep -e 'Escape character'|wc -l
if [ ${numcount} == 1 ];then
echo -e “访问${ipaddress}:${port}成功,无异常!”
let countsuccess+=1
else
echo -e “访问${ipaddress}:${port}失败,检查ip和port是否正确!”
let countfail+=1
fi
sleep 2
done
succesper=$((${countsuccess}100/${total}))
failper=$((${countfail}
100/${total}))
echo “总共执行次数${total},成功次数${countsuccess},成功比例${succesper}%,失败次数${countfail},失败比例${failper}%”

目录

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog