Perl Programming |
|||||||||
|---|---|---|---|---|---|---|---|---|---|
|
HOME HTML Tree Enhancing vi Super Sorts Search Subdirs CPU Hogs |
|||||||||
|
Graphical df using Perl/TkI've been working on this script in various versions since 1996, but here at last is one I feel is sufficiently refined to make available. At the time I wrote this I was responsible for a corporate database and webserver, and needed to be able to tell at a glance if one of the several system disks was getting full. Granted, Berkeley df does a pretty good job of giving percentages in a hurry, but then, I also wanted to get a handle on Perl/Tk, a wonderful porting of the popular Tcl/Tk toolkit to Perl by Nick Ing-Simmons. Compared to building GUI code with an X11 library such as Athena or Motif, GUI development in a scripted language is a breeze. I highly recommend it for all small to medium-scale GUI applications. Using the object oriented features of Perl 5, even large-scale GUI applications are within reach. I decided to start small (and useful) however, with a pie-chart display of Disk Fullness.
So How Does it Work?gdf doesn't do anything terribly sophisticated for a Perl GUI application. It creates a scrolled canvas. It then runs the Berkeley version of df on your system, and captures the output. Each line returned is formatted into a new "segment" on the display. A segment consists of the following widgets:
The BasicsPerl/Tk is another name for a module for Perl called Tk.pm. There are several versions available. Jump to the CPAN Tk Module Directory to get a look at what's available. I recommend the latest version of Tk800 to get the full functionality of the graphics toolkit. The quickest way to get Tk installed is using the "-MCPAN" option for Perl. This tells Perl to download and install the module you need directly from CPAN. The only drawback is that if you're on an RPM dependent system, you'll have to remember to perform this command after restoring or reinstalling Linux. The command is:
If you haven't used -MCPAN with Perl before, you will be prompted with several questions at first. Most of them can be answered with the enter key (to accept the default). Programming with Perl/Tk is more straightforward than writing X11 graphics in C/C++ for several reasons. Here's a few of them:
Here's some sources for Perl/Tk documentation.
To Do...A couple of people who like gdf have requested that I include a button for updating the displayed information, or maybe have it periodically refresh the data it displays. I had not thought of making it work this way initially since it more or less duplicates the behavior of the df command graphically: run it once, get one set of output. However, I do see the point of allowing updates. If one leaves gdf on the display for a long time, it will cease to show up-to-date information. Addressing this requirement will be a significant update. The code which generates the pie arcs and text labels on the canvas will need to be encapsulated and moved to a separate subroutine (or callback) which can be executed independently of the initialization. In addition, "erase" routines may need to be added. These would be needed if simply re-drawing the pie arcs and labels is not sufficient to hide the remnants of the previous set. Download gdfClick here to download gdf. The above text and scripts are Copyright 2000 © by Scott Chilcote. |
||||||||
|
HOME HTML Tree Enhancing vi Super Sorts Search Subdirs CPU Hogs |
|||||||||