This page gives an example how to write PLUGIN in Expect for Proxy32 terminal. Most important thing to remember about PLUGIN is that PLUGIN process should communicate with the shell running in terminal via PLUGINs STDIN and STDOUT (using send_user
and expect_user
in Expect script) and print to user's terminal via PLUGINs STDERR (using send_error
in Expect script). Below is the code to be pasted into PLUGIN command line field:
expect -c '
#send command to shell
send_user "ssh belous@localhost\r\n"
#expect password prompt from ssh
expect_user "assword:"
#show to user terminal what was received from the shell
send_error "$expect_out(buffer)"
#send password to ssh prompt (use \$ instead of $)
send_user "testpassword123\r\n"
'
ssh
command to the terminal (as if user typed it there) and waits for ssh command to return prompt Password:
.Below is the code of the same plugin but without comments and with password replaced by substitution parameter, so that password is supplied on the start of the plugin via parameter input dialog instead of being stored in code of the plugin:
expect -c '
send_user "ssh belous@localhost\r\n"
expect_user "assword:"
send_error "$expect_out(buffer)"
send_user "<PROXYPASSWORD=SSH server user password>\r\n"
'
More compact version is:
expect -c '
send_user "ssh belous@localhost\r\n";expect_user "assword:";send_error "$expect_out(buffer)"
send_user "<PROXYPASSWORD=SSH server user password>\r\n"
'
Expect is installed as part of Proxy32 built-in CYGWIN installation and path to the /bin folder of the CYGWIN installation (where perl and expect interpreters are located) is automatically included into Proxy32 environment. So, when PLUGIN is executed by Proxy32, PLUGIN command line can start with just expect
and the Expect interpreter will be found.