Using conditional statements inside ‘expect’

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

Don’t make me manually abort a LaTeX compile when there’s an error

With MikTeX, pdflatex has this command-line option: -interaction=MODE Set the interaction mode; MODE must be one of: batchmode, nonstopmode, scrollmode, errorstopmode. Edit suggested by @9999years: Those values are equivalent to a set of LaTeX \commands that provide the same functionality. From TeX usage tips: The modes make TeX behave in the following way: errorstopmode stops … Read more

Use Expect in a Bash script to provide a password to an SSH command

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

tech