在shell脚本中调用expect脚本函数

时间:2015-03-06 16:26:30

标签: bash shell expect

  • 我对tcl编程很新。我正在尝试将expect脚本编写为shell脚本中的函数
  • 现在使用的shell函数有一组expect命令要执行。
  • 这些期望命令可以被分成一个小的期望函数,需要用作shell函数内的子函数

我使用了以下内容:

#!/bin/bash
function auto_run
{
/usr/bin/expect<<EOF
#!/usr/bin/expect
proc guest_reboot {} { 
send "reboot\r"
expect "login" {
send "root\r"
expect "word:"
send "1234\r"
}
}
spawn ssh user@$1 
expect {
"active"
spawn ssh root@$1
expect -re "Escape"
send "\r"
expect "#"
guest_reboot
}
 default
{
send "\r"
guest_reboot
}
}
EOF
}
auto_run guest1

0 个答案:

没有答案