7

In this expect script there will be no ssh server connected, I just want to execute a ".sh" file locally, is that possible?

For instance:

#!/bin/expect

command "xxx.sh" # a command which starts a certain shell script

Also, is it possible to execute a expect script within a expect script?

For instance:

#!/bin/expect

command "xxx.exp" # a command which starts a certain expect script

Any help?

tod
  • 1,539
  • 4
  • 17
  • 43
user3636706
  • 197
  • 1
  • 2
  • 15
  • Why does it matter whether there's an SSH server connected? Expect has no special relationship with SSH. – Barmar May 14 '14 at 18:16

2 Answers2

6

If you need to interact with this script, use spawn xxx.sh

If you just need to run it and capture the output, use set output [exec xxx.sh]

Expect is an extension of the Tcl language, so you would be well served to go through the Tcl tutorial.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
5

The command in Expect to run a shell command is spawn.

#!/bin/expect
spawn command arg1 arg2 ...

command can be any program -- a binary executable, a shell script, another expect script, etc. So you can do:

spawn xxx.sh

or:

spawn xxx.exp
Barmar
  • 741,623
  • 53
  • 500
  • 612