python/psutil/examples/who.py

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c79548b4411c
1 #!/usr/bin/env python
2
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.
6
7 """
8 A clone of 'who' command; print information about users who are
9 currently logged in.
10 """
11
12 import sys
13 from datetime import datetime
14
15 import psutil
16 from psutil._compat import print_
17
18
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 )
28
29 if __name__ == '__main__':
30 main()

mercurial