Run the following command to execute the following documents and experiments on the Internet:
Keep CT-F expect-ssh.exp <username> <password>
Note that in this expect-ssh.exp, the connect function is mainly responsible for login, the last two lines of code, the two send is the login, the execution of the command, note that at last must execute an exit, otherwise, the secondary CT will remain on the remote host after execution.
Here is the source code of the expect-ssh.exp: Proc usage {}{
Puts stderr "usage :$: argv0 Username Password IPaddress"
Exit 1
}
Proc connect {pass }{
CT {
"(Yes/No )? "{
Send "Yes \ n"
Reset CT "* password :"{
Send "$ Pass \ n"
CT {
"*#"{
Return 0
}
}
}
}
"* Password :"{
Send "$ Pass \ n"
CT {
"*#"{
Return 0
}
}
}
}
Return 1
}
If {$ argc! = 3} {usage}
Set username [lindex $ argv 0]
Set Password [lindex $ argv 1]
Set hostip [lindex $ argv 2]
Spawn SSH $ {username }@$ {hostip}
If {[connect $ Password]} {
Exit 1
}
Send "RM-F/root/testeric; RM-F pattern_file \ n"
Send "Exit \ n"
CT EOF