Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Quick easy and dangerous - automated logins via Tcl / Expect

Let me start with a security warning. Passwords and firewalls are there to make it difficult for unauthorized users to get through / at systems, and if you write a script which automates passwords and multi-hop telnet and ssh logins to make it quick and easy for you to get over all the hurdles you are also making it easy for everyone else who has access to a copy of your script. In other words, use what I am about to show you with great care and keep the script if you embed passwords and save names in it with extreme care!

OK. Now let me spill the beans. If you want to automate a login process so that you get straight in to a remote system though what might be a difficult series of steps, you can do so using expect. Once logged in, you can use the interact command within expect to connect your keyboard and screen to the remote process and talk to it directly.

Let's make the connection:

spawn ssh -l accountname www.melkshamchamber.org.uk
expect_after {
   default {
     puts "Failed to connect"
     exit 1
expect "sword:" {send "abc123_not_really\r"}
expect "\$ " {send \r}
expect "\n"
puts "connected ...."

And then you can simply:


Interact has a series of options / matching capabilities just like the expect command itself, though, and you can apply filters on what you type. There's an example here - automating ssh and with filters and further examples here (telnet) and here (telnet, filtering, logging, etc)

But let me finish as I started. A script that makes it trivially easy for YOU to log in also makes it trivially easy for anyone who has stolen your script to log in!
(written 2009-10-24)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T242 - Tcl/Tk - More on Expect
  [435] Expect for Windows - (2005-09-04)
  [1173] Cheat Sheet / Check list for Expect maintainers - (2007-05-02)
  [1411] Buffering of inputs to expect, and match order - (2007-10-27)
  [1475] Tcl/Tk - updating your display while tasks are running - (2007-12-16)
  [1531] Expecting a item from a list of possibles - (2008-02-04)
  [3009] Expect in Perl - a short explanation and a practical example - (2010-10-22)
  [3448] Checking all the systems on a subnet, using Expect and Tk - (2011-09-18)

Back to
Using Tcl and Expect to automate repetitive jobs
Previous and next
Horse's mouth home
Forward to
Tcl - uplevel to run code at calling level
Some other Articles
Accidentally typed ci rather than vi?
How did I do THAT?
By train ...
Tcl - uplevel to run code at calling level
Quick easy and dangerous - automated logins via Tcl / Expect
Using Tcl and Expect to automate repetitive jobs
Exploring Old Railways
split and join in tcl and expect
A short form of if ... then ... else
Windows 7 and Open Source Programming
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2475_Qui ... xpect.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb