解决shell脚本中 telnet ap自动输入用户名和密码以及回车符

时间:2021-04-14 09:16:50
#!/bin/bash
function change_ap {
(
s=`stty -g`;
str=$"\n"
sstr=$(echo -e $str)
stty raw -echo;
sleep 2;
echo "xxxx";
sleep 2;
echo "xxxxx";
sleep 2;
echo "system-view";
sleep 2;
echo "wlan service-template 3 crypto";
sleep 2;
echo "service-template disable";
sleep 2;
echo "ssid 8888888";
sleep 2;
echo "service-template enable";
sleep 2;
echo "save";
sleep 2;
echo "Y";
sleep 2;
echo "$sstr";
sleep 2;
echo "Y";
dd bs=1 cbs=1;
stty $s
) | telnet 172.16.1.251 | cat
}
change_ap