使用脚本进入一个命令行控制台,并预设执行的命令列表

参考1:https://codeday.me/bug/20170628/32557.html

参考2:https://avdeo.com/2009/08/14/spawn-expect-send-and-interact/

 

主要是使用Unix内置的expect程序。

在脚本之前  写 #!/usr/bin/expect 或 #!/usr/bin/expect -f 均表明该脚本使用expect执行。

expect可以识别spwn,expect,interact,send等命令,还有set promt等。

使用spwn命令启动一个外部程序。

使用expect等待将要出现的字符串,可以使用通配符,只有出现了匹配的字符串,才继续执行脚本中下一条命令。

使用send发送需要外部程序执行的命令。

 

 

man7上有详细介绍 http://man7.org/linux/man-pages/man1/expect.1.html

 

posted on 2019-04-01 11:14  longbigfish  阅读(327)  评论(0编辑  收藏  举报

导航