[logo] pyutmp - Python binding for Unix utmp file

Download

To obtain my PGP/GnuPG key, see these instructions.

Documentation

Back to software page.

Introduction

The pyutmp module provides a Python-oriented interface to the utmp file on Unix-like operating systems. To paraphrase the Linux Programmer's Manual page utmp(5), the utmp file allows one to discover information about who is currently using (i.e., is logged into) the system. The utmp file is a series of entries whose structure is typically defined by the "utmp.h" C header file.

This module provides an read-only interface to the underlying operating system's C utmp API.

Interface and Usage

The pyutmp module supplies two classes: UtmpFile and Utmp. A UtmpFile object represents the open utmp file; when you iterate over a UtmpFile object, it yields successive Utmp objects. For example:
from pyutmp import UtmpFile
import time

for utmp in UtmpFile():
    # utmp is a Utmp object
    if utmp.ut_user_process:
        print '%s logged in at %s on tty %s' % (utmp.ut_user, time.ctime(utmp.ut_time), utmp.ut_line)
Please see the API documentation for more details.

Notes

This module has been tested on the following operating systems:
  • Ubuntu Linux, version 8.04
  • Gentoo Linux, version 2008.0 (tested by Joel Davis <dejoelness @ gmail.com>. Thanks, Joel.)
  • FreeBSD
  • Mac OS X
  • Open Solaris, using the Sun Studio 12 compiler suite and Python 2.5
Adding support for other Unix variants should be straightforward.

This package uses Cython to generate the C source files that serve as the Python utmp extensions.

Installation

The usual:

  1. Unpack the tarball or Zip file.
  2. Change your directory to the resulting pyutmp-0.2 directory.
  3. Run: python setup.py install
This module is also available on PyPI. If you have Easy Install installed, you can install this package with one command (usually as root):
easy_install pyutmp

Source Code Repository

The source code for pyutmp is maintained on github. To clone the repository, run this command:

git clone git://github.com/bmc/pyutmp.git

Author

Brian M. Clapper, <bmc @ clapper . org>

Copyright

© 2008 Brian M. Clapper

License

BSD-style license. See accompanying LICENSE file.