Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a expect script while connecting to a ssh server

Tags:

expect

For example, now I have a "root.exp" expect script as following:

spawn ssh user@ip
expect "Password:"
send "password"

Then, the expect command I want to send to this ssh server is stored in another expect script file branch.exp, which for example is as following:

expect ">>"
send "ls"

My question is, how to call this branch.exp in root.exp? For example, something like following in the root.exp:

spawn ssh user@ip
expect "Password:"
send "password"

*call* branch.exp
like image 754
user3636706 Avatar asked Jan 25 '26 17:01

user3636706


1 Answers

As Johannes said, you can use the source command. The Expect and TCL mini reference manual says:

source Procedures and variables can be stored in other files and read using the source command. As the file is read, the commands are executed.

Example:

source ~/def.tcl
like image 175
Ortomala Lokni Avatar answered Jan 29 '26 20:01

Ortomala Lokni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!