expect简介(需要包expect)
基于TCL编写的自动交互式程序
-可以用在Shell脚本中,为交互式过程自动输送预先准备的文本或指令,而无需人工干预
-触发的依据是预期会出现的特征提示文本
举例:
[root@server0 ~]# cat test11.sh
#!/bin/bash
expect << EOF
spawn ssh 172.25.0.10
expect "password" {send "redhat\n"}
expect "#" {send "touch /xx.x\n"}
expect "#" {send "exit\n"}
EOF
[root@server0 ~]# sh test11.sh
脚本注意:
1.没有expect
2.指定一个需要交互的程序
3.最后一行代码不执行