[CentOS7]expect telnet
- 交换机管理 登录账号密码很长输入很不方便
cat > tl.sh <<'EOF'
#!/usr/bin/expect
#set passwd "12345678\n"
set timeout 20
# 外部传递参数
set host [lindex $argv 0]
spawn telnet $host
expect {
"oot:"
{
send "root\n"
expect "*assword:" { send "www.example.com\n"}
}
"*assword:"
{
send "www.example.com\n"
}
}
# 提供交互
interact
# 匹配后退出
#expect eof
EOF
- 使用
chmod +x ./tl.sh
./tl.sh 172.16.0.1