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))
What is running on your network? (tcl and expect)

Earlier this week, I gave a much-tailored Tcl course, with a strong helping of expect.

Expect adds three major extra commands to Tcl - spawn to start a new process under the control of the running Tcl/Tk code, send to send information to it and expect to await for - and decide on how to process - a particular response. It is a very clever way to automate other process which are designed for keyboard use, and otherwise very hard to automate.

Here's an example - written largely during the course, and which I ran (when I got back to base) to test our own network at Well House Manor which pings a whole series of hosts in turn, and then analyses their response to give a summary of what is up and running.

log_user 0
 
set iplist "67 99 134"
for {set k 210} {$k<223} {incr k} {
 lappend iplist $k
 }
 
foreach lastbit $iplist {
 
spawn ping -c2 192.168.200.$lastbit
puts -nonewline "testing $lastbit ... "
flush stdout
 
# expect is like a switch ;-)
 
expect {
 "2 packets received" {
  set between $expect_out(buffer)
  regexp {time=([^\n]+)} $between all actual
  puts "Present - sample timing - $actual"
  set located($lastbit) $actual
  }
 "packets received" { puts "POOR"}
 timeout { puts UNFOUND}
 eof { puts GONEAWAY}
 }
}
 
puts "--------------- System Available Summary ---------"
foreach host [lsort -integer [array names located]] {
 puts "192.168.200.$host"
 }
exit
 
--- Since Tcl is a truly interpretive language, I can
add any comments - or this sample output - below my
exit command, and it this text won't every be interpreted
 
testing 67 ... Present - sample timing - 2.054 ms
testing 99 ... Present - sample timing - 0.114 ms
testing 134 ... Present - sample timing - 4.521 ms
testing 210 ... UNFOUND
testing 211 ... UNFOUND
testing 212 ... UNFOUND
testing 213 ... UNFOUND
testing 214 ... UNFOUND
testing 215 ... Present - sample timing - 294.033 ms
testing 216 ... UNFOUND
testing 217 ... UNFOUND
testing 218 ... Present - sample timing - 103.647 ms
testing 219 ... UNFOUND
testing 220 ... UNFOUND
testing 221 ... UNFOUND
testing 222 ... Present - sample timing - 5.454 ms
--------------- System Available Summary ---------
192.168.200.67
192.168.200.99
192.168.200.134
192.168.200.215
192.168.200.218
192.168.200.222


Now ... that's a slow process, as each failing connection times out in series. Which is ironic, because the time at which you want a faster response is when you have systems down / network issues.

Using a list of spawn_ids, Expect can run a whole series of processes in parallel and can wait on any one of them, knowing which one has responded and processing it as appropriate. There's a complete example I've written of this available on our web site [source code link] and it's covered during our public Tcl course; the version I've linked to is for Mac OS X (ping's responses vary by operating system) - if you're looking for versions that run on various Linux distributions, you'll find links to them from the Mac page.

Finally, I have a screen capture of a web-based version in which I've done no more that add in some Common Gateway Interface code. And this means that I can check out our intranet from any browser - "what machines are running" I can ask.

The default setup tests my servers (at 192.168.20.67, 99 and 222), my outbound connection (at .134) and our fleet of training systems - so that you can see that this evening we have a functioning network connection box, a server, and two "late bird" systems - "Easterton" at .215 and "Holt" at .218

I've already received a request to annotate the display ;-) .... which I will indeed do - so that the page gives a very much more graphic report of our network, with machine names and functions included and flags up whether or not we're on line, and so on. Easy to do, but it'll obfuscate the source code demonstration a little.





(written 2008-09-04, updated 2008-09-05)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T241 - Tcl/Tk - Tcl on the Web
  [2040] Error: Cant read xxxxx: no such variable (in Tcl Tk) - (2009-02-14)
  [2238] Handling nasty characters - Perl, PHP, Python, Tcl, Lua - (2009-06-14)
  [2429] Tcl scripts / processes on a web server via CGI - (2009-09-27)
  [4461] Reading from a URL, and reading Json, from your Tcl script - (2015-03-12)

T212 - Tcl/Tk - Expect Processes
  [287] Checking that all our servers are up and accessible - (2005-04-22)
  [675] Adding PHP tags to an old cgi program - (2006-04-08)
  [1173] Cheat Sheet / Check list for Expect maintainers - (2007-05-02)
  [2474] Using Tcl and Expect to automate repetitive jobs - (2009-10-24)
  [2489] Parallel Pinging, using Python Threads or Expect spawn lists - (2009-11-02)
  [3448] Checking all the systems on a subnet, using Expect and Tk - (2011-09-18)
  [4678] Expect with Ruby - a training example to get you started - (2016-05-18)


Back to
Global - Tcl, PHP, Python
Previous and next
or
Horse's mouth home
Forward to
Picturing the rain
Some other Articles
Looking for a value in a list - Python
Python 2 to Python 3 / Python 3000 / Py3k
Howto - write and manage a news box on your web page
Picturing the rain
What is running on your network? (tcl and expect)
Global - Tcl, PHP, Python
Think before you send
Calling procs in Tcl and how it compares to Perl
Reception
Server overloading - turns out to be feof in PHP
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/1785_Wha ... pect-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb