Tuesday, September 13, 2011

Automating a telnet to a remote system using expect script and running a application

This program i have written to telnet to a remote system and run a applet in that remote system.And exit from the remote host once the expect script receives "zzz" from the applet.


!/usr/bin/expect
log_file -a /tmp/expectlog     <---all the interactions in the remote system are saved in this file
set timeout 60
spawn telnet   122.23.33.33
expect "login:"
send "xxxxx\n"                     <-----username
expect "Password:"         
send "fdfdfdffd\n"                 <-----password                 
expect "xxxxx"                       <---prompt expected after login
send "\n"
send "appletviewer  applet.html\n"
interact -o "zzz" return            <-----to come out of the interact mode once the expect receives "zzz" from the application
send "exit\r"                            <------to exit from the telnet session
expect eof {puts "finished "}    <------expecting eof when the spawn process completes
exit 0                                      <-----ending the expect script

No comments:

Post a Comment