shell expect


expect的核心是spawn、expect、send、set。


spawn调用要执行的命令


expect监听交互输出


send进行交互输入


set设置变量值


interact交互完后,将控制权交给控制台


expect eof,与spawn对应,表示捕捉终端输出信息终止,类似if…endif

#!/bin/bash

passwd=“123456”

cat iplist |while read line

do

/usr/bin/expect <<EOF

set timeout 10

spawn ssh root@KaTeX parse error: Can't use function '\r' in math mode at position 51: …no" { send "yes\̲r̲";exp_continue …passwd\r"}

    }

   expect "]#"


   send "ifconfig\r"

   send "exit\r"

   expect eof

EOF

done

exit 0

shell expect免交互操作#yyds干货盘点#_bash