Python System Admin Utilities
Over the past few years, I've written some utilities to solve certain problems I've encountered. There are all written in Python and require a Python interpreter (version 2.4 or later) to run. Here are a few sources freely-downloadable Python distributions.
- The Official Python Web Site. This is the standard Python distribution, with binaries and source code.
- Activestate ActivePython. This is the distribution I use on Windows. Packages are available for Windows, MAC, Linux, and some Unix flavors. The Windows distribution includes Windows-specific APIs and bindings, as well as a much better Integrated Development Environment (IDE) than comes with the standard distribution.
- Enthought Enhanced Python for Windows. Windows-specific distribution that comes with everything but the kitchen sink. I haven't used this one, but it looks interesting.
I've used all of these in Windows, but haven't tested most on Unix. Since Python is a cross-platform language they should run on Unix, unless there's something Windows-specific about them. I've noted where the utility is written for a specific Operating System.
These utilities are covered by the GNU General Public License, version 2.0 (or later).
It doesn't take a lot of looking at the code for these utilities to see that I'm not a world-class software developer. I tend toward writing procedural code and commenting heavily, so that years after writing a program I can figure it out to debug or modify it. It helps that Python is a language for which readability is a key feature. If you want to see really tight, concise code, you're in the wrong place.
- Groomer.py. Deletes old files. You don't have to syslog an enterprise firewall for long to see how large log files become. After a while the data is useless, unless you're anal about retaining them for posterity, and archives can quickly exhaust hard drive space. Groomer.py deletes files over X days old, with an option for filename pattern matching from a directory. I usually run it once a week on the system scheduler to delete log archived files over 90 days old. This is a great companion to use with Kiwi Syslog Daemon.
- ReadFromZip.py. Ever need to read the data from a large text file that's been "zipped"? Kiwi Syslog Daemon has a great capability to archive syslogs to .ZIP archives to save hard drive space. So you need to get data out of that 500MB log file from 3 weeks ago that's been "zipped" to an archive file? ReadFromZip.py was designed just for that! It can list the files in an archive or read the content of a specific file from an archive to the screen. What makes it nice is that you can redirect the output to a file or pipe it through "grep" (using these great, free Unix Utilities for Windows) to directly filter data coming out of the .ZIP archive, with the result that you can extract filtered data from a "zipped" file without actually opening the .ZIP archive (the built-in Python module for .ZIP files streams data directly from the archive
without having to open the whole thing the way other software does. As a result, it uses litle memory and it's scary fast!). The code isn't Windows-specific, but .ZIP files are seldom found on any platform except Windows.
- TCPing.py. "Pings" hosts using TCP rather than ICMP, so you can "ping" across firewalls to Web and E-mail Servers. Defaults to TCP port 80 (HTTP) and is fairly configurable. Doesn't provide round-trip time info (Sorry).
- Unixtime.py. Unix timestamps seem to show up in more and more things. Ever try to figure out what a Unix timestamp means? Unixtime.py takes a Unix timestamp off the command line and provides human readable date and time, without correcting for your local timezone (i.e., the absolute time represented by the timestamp. By commenting/uncommenting 2 lines, you can get the absolute time represented by the timestamp, shift to your local timezone.).
- Dirsync.py. One-way directory/file synchronization from a source folder to a destination folder. We use a NAS box as a transition point between systems. I created program this because I got tired of modifing batch files every time a folder was added or deleted. It creates/deletes files and directories on the destination as required to make the destination look just like the source. It requires that both the source and destination be mounted, either locally or across a network. It should work cross-platform, but I've only tested it on Windows..
If you find any of these utilities useful, then when you speak of me, speak well. If not, at least speak nicely...
Copyright 2001-2009, Tim Sharpe. You are free to use this information for personal, non-commerical use without restriction. All rights reserved for commerical, organizational, or government use. Questions or comments to email@example.com. Flames to /dev/nul.
visits since July 14, 2008