[wplug] Bash Expect usage - Automating telnet

G.Pitman gpitman at gmail.com
Fri May 9 15:43:10 EDT 2014


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
>


More information about the wplug mailing list