在shell脚本中使用Telnet登录进去软件并执行命令

function check_elb_icp()
{
cat ${net_name}_iplist_elb.txt | while read ipline;
do
vm_name=`echo $ipline |awk -F',' '{print $1}'`
ip=`echo $ipline |awk -F',' '{print $2}'`
soft=`echo $ipline |awk -F',' '{print $3}'`
port=`echo $ipline |awk -F',' '{print $4}'`
user=`echo $ipline |awk -F',' '{print $5}'`
pass=`echo $ipline |awk -F',' '{print $6}'`

echo ${vm_name} ${ip} ${port} ${user} ${pass}

####elb的ICP通道####
(
sleep 1
echo -e "${user}\r\n"
sleep 1
echo -e "${pass}\r\n"
sleep 1
echo -e ":display-icp-state;\r\n"
sleep 1
echo -e "exit\r\n"
)|timeout 10 telnet ${ip} ${port} >./temp/elb_temp11.txt


echo " ********${vm_name}*********${ip}***${port}***${soft}******" >> ${elb_file}
sed -n "/^ELB\[/,/exit/p" ./temp/elb_temp11.txt >> ${elb_file}
echo "**************************************************************" >> ${elb_file}
echo " " >> ${elb_file}

echo " ********${vm_name}*********${ip}***${port}***${soft}******" >> ${version}
sed -n "4p" ./temp/elb_temp11.txt >> ${version}
echo " " >> ${version}

done
}

check_elb_icp

posted @ 2022-07-20 11:55  新茶煮酒  阅读(1397)  评论(0编辑  收藏  举报