pyutmp

Python UTMP wrapper for Un*x systems
Download

pyutmp Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Brian M. Clapper
  • Publisher web site:
  • http://www.clapper.org/

pyutmp Tags


pyutmp Description

Python UTMP wrapper for Un*x systems pyutmp is a Python module that provides an 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 UtmpFileimport timefor 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)UtmpFileIn addition to the __iter__() generator method, allowing iteration over the contents of the utmp file, the UtmpFile class also provides a rewind() method that permits you to reset the file pointer to the top of the file. See the class documentation for details.UtmpThe fields of the Utmp class are operating system-dependent. However, they will always include at least the following fields:ut_user str The user associated with the utmp entry, if any.ut_line str The tty or pseudo-tty associated with the entry, if any. In this API, the line will always be the full path to the device.ut_host str The host name associated with the entry, if any.ut_time timestamp The timestamp associated with the entry. This timestamp is in the form returned by time.time() and may be passed directly to methods like time.ctime().ut_user_process bool Whether or not the utmp entry is a user process (as opposed to a reboot or some other system event).On some operating systems, other fields may be present. For instance, on Linux and Solaris systems (and other System V-derived systems), Utmp also contains the following fields:ut_type str The type of the entry, typically one of the following string values: "RUN_LVL", "BOOT_TIME", "NEW_TIME", "OLD_TIME", "INIT_PROCESS", "LOGIN_PROCESS", "USER_PROCESS", "DEAD_PROCESS", "ACCOUNTING". See the utmp(5) manual page for a description of these valuesut_pid int Associated process ID, if any.ut_id str The init(8) ID, or the abbreviated tty name.ut_exit_code int Process exit code, if applicable.ut_session int Session ID, for windowing.ut_addr int array IPv4 address of remote host (if applicable), one octet per array element.If you're writing portable code, you should not count on the presence of those attributes--or, at the very least, you should wrap access to them in a try/catch block that catches AttributeError. Requirements: · Python


pyutmp Related Software