expect script to automate telnet login
My bad. The problem was with the curly braces. They are supposed to be at the same line as the expect command .
My bad. The problem was with the curly braces. They are supposed to be at the same line as the expect command .
The code should read the contents of the two files into lists of lines, then iterate over them. It ends up like this: # Set up various other variables here ($user, $password) # Get the list of hosts, one per line ##### set f [open “host.txt”] set hosts [split [read $f] “\n”] close $f # … Read more
Ruby comes with the PTY module for setting up pseudoterminals to drive interactive command line applications. With it comes an expect method that allows you to interact with an application kinda like Expect. For learning how to use expect, I found “What to expect from the Ruby expect library?” helpful. As far as gems go, … Read more
Use expect’s stty command like this: # grab the password stty -echo send_user — “Password for $user@$host: ” expect_user -re “(.*)\n” send_user “\n” stty echo set pass $expect_out(1,string) #… later send — “$pass\r” Note that it’s important to call stty -echo before calling send_user — I’m not sure exactly why: I think it’s a timing … Read more
Have to recomment the Exploring Expect book for all expect programmers — invaluable. I’ve rewritten your code: (untested) proc login {user pass} { expect “login:” send “$user\r” expect “password:” send “$pass\r” } set username spongebob set passwords {squarepants rhombuspants} set index 0 spawn telnet 192.168.40.100 login $username [lindex $passwords $index] expect { “login incorrect” { … Read more
I always used the “proper” solution, but I used expect in other situations. Here I found following suggestion: #!/usr/local/bin/expect spawn sftp -b cmdFile [email protected] expect “password:” send “shhh!\n”; interact
I spent some time on this and succeeded. I found this blog during research, and decided to return and provide my solution to save the next guy some time. I’m responding as a guest with a false email so I won’t be interacting, but no further information should be required. On Jul 18 ’12 at … Read more
Basically, in this example I wanted to get some variable values in particular places of the code; and have them output until the program crashes. So here is first a little program which is guaranteed to crash in a few steps, test.c: #include <stdio.h> #include <stdlib.h> int icount = 1; // default value main(int argc, … Read more
Mixing Bash and Expect is not a good way to achieve the desired effect. I’d try to use only Expect: #!/usr/bin/expect eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no usr@$myhost.example.com # Use the correct prompt set prompt “:|#|\\\$” interact -o -nobuffer -re $prompt return send “my_password\r” interact -o -nobuffer -re $prompt return send “my_command1\r” interact -o -nobuffer -re … Read more