Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a shell script within "expect script"?

Tags:

expect

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?

like image 761
user3636706 Avatar asked May 14 '14 18:05

user3636706


People also ask

How do I run a command in Expect script?

The first line defines the expect command path which is #!/usr/bin/expect . On the second line of code, we disable the timeout. Then start our script using spawn command. We can use spawn to run any program we want or any other interactive script.

How do you pass arguments to Expect script?

Arguments can be passed to the script when it is executed, by writing them as a space-delimited list following the script file name. Inside the script, the $1 variable references the first argument in the command line, $2 the second argument and so forth. The variable $0 references to the current script.


1 Answers

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.

like image 199
glenn jackman Avatar answered Sep 19 '22 15:09

glenn jackman