Jump to Navigation

186 - Expect Command Tool

Expect is a tool for scripting interactive command-line tools.

In general, Expect is useful for running any program which requires interaction between the program and the user. All the interaction can be
characterized programmatically. Expect can also give the user back control (without halting the program being controlled) if desired.
Similarly, the user can return control to the script at any time.

# expect -c 'spawn ssh user@remote.host ; expect password ; send "passphrase\n" ; interact'

or

#!/usr/bin/expect

set timeout 5
spawn ssh www.hoge.com
expect "Enter passphrase for key"
send "mypassword\n"
expect "Last login"
send "ls -l\n"
interact

 

Linux:


Main menu 2

Story | by Dr. Radut