linux expect

1.安装expect。

yum install expect

2.创建脚本test.sh, 内容为:

#!/usr/bin/expect  /*
set timeout 30
spawn ssh [email protected]
expect {
        "*yes/no*" { send "yes\r"; exp_continue }
        "*assword:*" { send "123456\r" }
}
expect "*#*"
send "ls \r"
 
send "exit\r"
expect eof
exit

第二行 为设置超时时间30s

3.执行脚本 获取信息

./test.sh |grep "123"


你可能感兴趣的:(linux expect)