python/psutil/examples/who.py

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rwxr-xr-x

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 #!/usr/bin/env python
     3 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
     4 # Use of this source code is governed by a BSD-style license that can be
     5 # found in the LICENSE file.
     7 """
     8 A clone of 'who' command; print information about users who are
     9 currently logged in.
    10 """
    12 import sys
    13 from datetime import datetime
    15 import psutil
    16 from psutil._compat import print_
    19 def main():
    20     users = psutil.get_users()
    21     for user in users:
    22         print_("%-15s %-15s %s  (%s)" % \
    23             (user.name,
    24              user.terminal or '-',
    25              datetime.fromtimestamp(user.started).strftime("%Y-%m-%d %H:%M"),
    26              user.host)
    27         )
    29 if __name__ == '__main__':
    30     main()

mercurial