[wplug] Bash Expect usage - Automating telnet

Ben Beige dariuscardren at gmail.com
Mon May 12 11:44:02 EDT 2014


besides MUDs I am not sure other than testing another service
(HTTP/POP/etc...). Most things are fairly deprecated that used telnet.



Ben Beige
dariuscardren at gmail.com


On Mon, May 12, 2014 at 11:40 AM, Pat Barron <pat at lectroid.com> wrote:

> I'm not particularly familiar with expect, myself, but if your script is
> literally as you have indicated below, it has some quoting problems.  I
> tried the script (as written below) and get the same failure.  The
> script gets further after fixing the double-quotes on line 6 and line 7,
> escaping the double-quotes (putting a '\' character in front of them, as
> you've done later in the script with the subsequent expect functions).
>
> I can't test it too much more than this, since I was doing my testing on
> a Windows system under Cygwin (without the Cygwin "telnet" client
> installed), and because these days I can't really think of anything I
> can actually telnet to.  ;-)
>
> --Pat.
>
> On 5/12/2014 9:26 AM, scoob8000 wrote:
> > ssh isn't an option since these are just low end devices.  They only
> > support telnet or http.
> >
> > I can't even get it to spawn the telnet session, I'm sure it's something
> > simple in my syntax that I'm missing.
> >
> > Here's what I get:
> > missing close-bracket while executing "if [catch spawn"
> > couldn't read file "telnet": no such file or directory
> >
> > I'll take a look at autoexpect.
> >
> >
> > On Fri, May 9, 2014 at 3:43 PM, G.Pitman <gpitman at gmail.com> wrote:
> >
> >> You could give autoexpect a try
> >>
> >> http://linux.die.net/man/1/autoexpect
> >>
> >>
> >> On Thu, May 8, 2014 at 8:09 AM, scoob8000 <scoob8000 at gmail.com> wrote:
> >>
> >>> So I've never used expect before and I'm really struggling.   I'm
> >>> trying to come up with a script to telnet into a bunch of devices, run
> >>> a few commands then log it.
> >>>
> >>> I'm eventually going to have it read a list of IP's, and using the
> >>> exit status of the telnet put the IP address in either a pass.txt or
> >>> fail.txt logfile.   That part I should be able to figure out.
> >>>
> >>> Here's what I have now based off of some examples I found online.
> >>>
> >>> I think I'm missing something pretty simple here, but I'm stumped.  :)
> >>>
> >>>
> >>> #!/bin/bash
> >>> host=$1
> >>> export HISTIGNORE="expect*";
> >>> expect -c "
> >>> set timeout 20
> >>> if [catch "spawn telnet $host" reason] {
> >>> send_user "failed to spawn program: $reason\n"
> >>> exit 1
> >>> }
> >>>
> >>> expect \"Password:\"
> >>> send \"oldpasswordr\"
> >>> expect \"Router>\"
> >>> send \"sys password newpassword\"
> >>> expect \"save ok, new password saved...\"
> >>> send \"sys cur2def\r\"
> >>> expect \"OK"\"
> >>> send \"exit\r\"
> >>> expect eof"
> >>> export HISTIGNORE="";
> >>> _______________________________________________
> >>> wplug mailing list
> >>> wplug at wplug.org
> >>> http://www.wplug.org/mailman/listinfo/wplug
> >>>
> >> _______________________________________________
> >> wplug mailing list
> >> wplug at wplug.org
> >> http://www.wplug.org/mailman/listinfo/wplug
> >>
> > _______________________________________________
> > wplug mailing list
> > wplug at wplug.org
> > http://www.wplug.org/mailman/listinfo/wplug
>
>
> _______________________________________________
> wplug mailing list
> wplug at wplug.org
> http://www.wplug.org/mailman/listinfo/wplug
>


More information about the wplug mailing list