Python: Get A Grip On Linux

This low-key, open-source scripting language is earning a reputation as a powerful tool for performing LInux configuration, management, and automation tasks.

InformationWeek Staff, Contributor

March 24, 2005

4 Min Read

The Python scripting language is gaining widespread acceptance as a tool used in the configuration and maintenance of Linux. Python has been compared to PERL in terms of its applicability, but it has branched out into the application space. One of the unique aspects of Python is that it constrains the user to a specific indentation format. This makes reading programs and short scripts a less time-consuming proposition when compared to other languages, such as C and C++.

Solution providers may find it useful to spend some time familiarizing themselves with Python, as it can greatly ease many tasks commonly performed to maintain Linux systems. I have made frequent use of small Python programs, run as "Cron" jobs, to do everything from taking database snapshots and performing a backup to periodically querying Web pages to check the status of remote content. That is an area where Python excels. The basic language elements are simple, but the extensive libraries that are available support everything from file and database access to HTML and XML parsing and construction.

If you are a solution provider maintaining several systems at a client site and you wish to be more proactive about monitoring application uptime, a simple Python script can be used to query the status of an application either through directly accessing the application, by reading a process-ID file or by other methods depending on the application. If there appears to be a problem with the application or system in question, it's a simple matter to send an e-mail to notify an administrator of the problem or communicate via XML-RPC to an issue-management system in order to create a support case. To more fully automate the task of checking any given system or application, the "Cron" command may be used to periodically run the Python script. This can be an extremely powerful tool not only to manage applications and systems, but also to increase the level of service a solution provider is able to offer to a client.

Python also contains an interactive shell. You may enter the Python shell by typing "python" at a shell prompt, provided it is installed on your system, of course. Once in the Python shell, commands are run as they are typed. This can be quite helpful in diagnosing problems on systems that require unique processing of some sort. For example, the standard "awk" tool can be used to parse simple text files, but if more complex parsing is needed, Python performs extremely well.

For the truly hard-core solution provider, C can be used to extend Python to do just about anything. I found one practical application for this when integration was needed with a third-party system that only provided a C-based API.

Python's Background

Python was created in the early 1990s by Guido van Rossum, who is still its primary author, although his efforts are supplemented by the contributions of many others worldwide. Python is governed by a "GPL-like" license, is completely open-source and is regulated by the Python Software Foundation, founded in 2001 by van Rossum with support from ActiveState, Zope and others.

If you're new to Python, it's definitely worth taking a few minutes to investigate its possibilities at the Web sites listed below. The documentation and libraries available for Python are extensive. In a few short hours, you can begin using Python to automate tasks, perform significant feats in the area of text processing and many other useful tasks.

Places to read more about Python:

  • www.python.org: the "official" Python site, offering downloads of software along with documentation and FAQs;

  • www.opensource.org: the nonprofit Open Source Initiative's (OSI) site, promoting OSI-certified software;

    www.sourceforge.net: a major repository of open-source code;

    www.zope.org: Python app-server site.

What's At the Library

Typical management and maintenance tasks can be performed easily with the wide variety of Python libraries that come with the standard system or are available as third-party, open-source add-ons:

  • HTML/XML aretrieval

  • Automated testing of systems and applications

  • Text processing

  • Zip file creation

  • Programmatic access to FTP and Gopher

  • SMTP and POP3 server access

  • Database access

Kevin Carlson ([email protected]) is with Watchfire, a business-management software and services provider based in Waltham, Mass.

Never Miss a Beat: Get a snapshot of the issues affecting the IT industry straight to your inbox.

You May Also Like


More Insights