[lug] Telnet with here document

Daniel Webb lists at danielwebb.us
Wed Apr 6 13:02:01 MDT 2005


On Wed, Apr 06, 2005 at 03:20:07PM +0200, rm at fabula.de wrote:

> #--------x snip x-----------------------------------------------
> #!/usr/bin/expect 
> 
> spawn telnet your.host.here
> sleep 5
> 
> # wait for the ogin prompt
> expect login
> 
> #send username
> send username\r
> 
> #wait for password prompt
> expect passw
> send password\r
> 
> send command\r
> 
> #--------x snip x-----------------------------------------------
> 
> [1] man 'expect' will give a good intro and there should be a rather
> good set of examples in the documentation folder of your distro.

I wanted to do exactly what you're talking about.  I found this
(modified by me) in the expect examples:

----
#!/bin/sh
# 
exec expect -- "$0" ${1+"$@"}
# Description: unbuffer stdout of a program
# Author: Don Libes, NIST
#
# dmw: This came from the expect examples directory
# example:
# (sleep 3; echo "password"; sleep 3; echo "ls -al"; sleep 5;) \
#    | unbuffer -p telnet -l user host
# Will non-interactively login to a telnet account and run ls -al

if {[string compare [lindex $argv 0] "-p"] == 0} {
    # pipeline
    set stty_init "-echo"
    eval spawn -noecho [lrange $argv 1 end]
    interact
} else {
    set stty_init "-opost"
    eval spawn -noecho $argv
    set timeout -1
    expect
}
----



More information about the LUG mailing list