[wplug] Bash Expect usage - Automating telnet

scoob8000 scoob8000 at gmail.com
Mon May 12 09:26:15 EDT 2014


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
>


More information about the wplug mailing list