File: who.py

package info (click to toggle)
python-utmp 0.7.4-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 176 kB
  • ctags: 189
  • sloc: python: 773; ansic: 568; makefile: 43; sh: 2
file content (18 lines) | stat: -rwxr-xr-x 412 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/python
# poor man's who

import utmp
from UTMPCONST import *
import time

a = utmp.UtmpRecord()

print "%-10s %-10s %5s %-25s %-20s" % ("USER", "TTY", "PID", "HOST", "LOGIN")

for b in a: # example of using an iterator
    if b.ut_type == USER_PROCESS:
        print "%-10s %-10s %5i %-25s %-20s" % \
        (b.ut_user, b.ut_line, b.ut_pid, 
         b.ut_host, time.ctime(b.ut_tv[0]))
a.endutent()