博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux expect
阅读量:6884 次
发布时间:2019-06-27

本文共 357 字,大约阅读时间需要 1 分钟。

hot3.png

1.安装expect。

yum install expect

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

#!/usr/bin/expect  /*

set timeout 30
spawn ssh root@192.168.202.216
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"

转载于:https://my.oschina.net/u/1445488/blog/350968

你可能感兴趣的文章