1.安装expect。
yum install expect
2.创建脚本test.sh, 内容为:
#!/usr/bin/expect /*
set timeout 30spawn ssh root@192.168.202.216expect { "*yes/no*" { send "yes\r"; exp_continue } "*assword:*" { send "123456\r" }}expect "*#*"send "ls \r" send "exit\r"expect eofexit第二行 为设置超时时间30s
3.执行脚本 获取信息
./test.sh |grep "123"