Training, Open Source Programming Languages

This is page http://www.wellho.net/mouth/3448_Che ... nd-Tk.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Checking all the systems on a subnet, using Expect and Tk

There are times that we want to check the connectivity of all the systems on our subnet - to see which machines are present, and which are not. Pinging them one at a time is a bit slow, but pinging them all at once in a simple script sets up too many connections and the script is likely to fall over. Then how do you display the results quickly and easily?

I have updated an "old favourite" script - "tkpingle" which check out a series of systems named on the command line - to test a complete subnet. Systems are "ping"ed 16 at a time, and layed out in a grid rather than a single column

Here's the initial display - with systems xxx.xxx.xxx.0 and xxx.xxx.xxx.255 greyed out as these are special "broadcast" addresses and not to be assigned to any system.


During operation, systems are tested out column by column. All systems still to be tested are shown in salmon, with systems going red as their test starts, then changing to orange, yellow and finally white if they respond to three pings. Note that the "run" button is disabled while the test is running.


When the testing is completed, the "run" button is re-enabled and the status report updated to show that the tests are complete. And I've turned the status report to yellow so that it's very clear to the user that the tests are completed.


The complete script is [here]

Some elements worthy of comment (even for people who have used a bit of Tk and expect before ...

* Making a grid uniform

The following - applied to one label in each row and each column - ensures that all cells are going to be of the same width and height.

  grid rowconfigure . .la_$syslab -weight 1 -uniform w
  grid columnconfigure . .la_$syslab -weight 1 -uniform w


* Closing out complete or incomplete pings

Spawning processes uses up system resources that need to be released if there's further resources needed (if there wasn't anything further to do, we could get away without doing this as the script will clean up on exit).

The use of catch is to avoid crashing the script if the script had closed the resource already, and the wait is to ensure that the resource truely is closed.

  foreach done $tidy {
    if { [catch {close -i $done} msg ] } {
      # ignore
    } else {
      wait -i $done
    }
  }


* Spawning parallel processes A

Processes that are spawned set their ID in the global variable $spawn_id. We save all the spawn_ids away so that we can check how all the processes are running in parallel later on.

  for {set k 0} {$k < 16} {incr k} {
    set val [expr $k + $j * 16]
    set system "$subnet.$val"
    spawn ping -c 3 $system
    set id($system) $spawn_id


* Modal buttons

In order to avoid a second series of test being started while the previous set is still running, we disable the "run" button as soon as its been pressed ...

  .redo config -state disabled

... and we re-enable it just as it finished its work.

  .redo config -state normal
(written 2011-09-18)

 
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)
  [2475] Quick easy and dangerous - automated logins via Tcl / Expect - (2009-10-24)
  [3009] Expect in Perl - a short explanation and a practical example - (2010-10-22)

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)
  [1785] What is running on your network? (tcl and expect) - (2008-09-04)
  [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)
  [4678] Expect with Ruby - a training example to get you started - (2016-05-18)

A163 - Web Application Deployment - Network Configuration and Security
  [11] A bolt of lightning on Multicasting - (2004-08-11)
  [37] Security and Safety - (2004-09-03)
  [267] Searching security holes - (2005-04-04)
  [332] Looking up IP addresses - (2005-06-01)
  [506] What are DHCP and DNS? - (2005-11-27)
  [511] Domain Forwarding - 2 ways of doing it - (2005-11-29)
  [1073] Heartbeat script in Perl - (2007-02-09)
  [1408] Wireless hotel tips - FTP and Skype connections failing - (2007-10-26)
  [1666] Slow boot and terminal start on Linux boxes - (2008-06-05)
  [1712] As different as night and tyres - (2008-07-18)
  [1904] Ruby, Perl, Linux, MySQL - some training notes - (2008-11-23)
  [2052] How was my web site compromised? - (2009-02-24)
  [4134] Setting up your MacBook Air as a mobile broadband router - (2013-07-07)


Back to
Needle in a haystack - finding the web server overload
Previous and next
or
Horse's mouth home
Forward to
Apache Internal Dummy Connection - what is it and what should I do with it?
Some other Articles
Which or ATOC - who reads train fares right?
Why would you want to use a Perl hash?
A threat in the post? Poor marketing practise from Smiletrain?
Apache Internal Dummy Connection - what is it and what should I do with it?
Checking all the systems on a subnet, using Expect and Tk
Needle in a haystack - finding the web server overload
Awk v Perl
Perl and CGI - simple form, and monitoring script.
Take the dog on a lead - do not carry her. Perl references.
Getting more log information from the Apache http web server
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).

© WELL HOUSE CONSULTANTS LTD., 2021: 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/3448_Che ... nd-Tk.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb