Search code examples
expect

Starting an Expect script within an Expect script


I am trying to run an Expect script within an Expect script (code below). However, I get the following error:

spawn ./script.exp
couldn't execute "./script.exp": no such file or directory
    while executing
"spawn "./script.exp""
    (file "./script.exp" line 7)

I have double checked and script.exp exists and is in the /home/user/scripts directory.

#!/usr/bin/expect

spawn ssh user@192.168.2.1
expect "$"
send "cd /home/user/scripts\r"
expect "$"
spawn "./script.exp"
expect "$"
send "logout\r"

Solution

  • Following the advice given in comments, using send "./script.exp\r"
    instead of spawn "./script.exp", fixes the problem.