File: last.py

package info (click to toggle)
python-utmp 0.8%2Bnmu1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 192 kB
  • ctags: 194
  • sloc: python: 796; ansic: 583; makefile: 41; sh: 2
file content (19 lines) | stat: -rwxr-xr-x 391 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/python
# poor man's last

import utmp
from UTMPCONST import *
import time

a = utmp.UtmpRecord(WTMP_FILE)

print ("%-10s %-10s %-30s %-20s" % ("USER", "TTY", "HOST", "LOGIN"))

while 1:
    b = a.getutent()
    if not b:
        break
    if b[0] == USER_PROCESS:
        print ("%-10s %-10s %-30s %-20s" % (b.ut_user, b.ut_line, b.ut_host, time.ctime(b.ut_tv[0])))
a.endutent()