1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/python/psutil/examples/who.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,30 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. 1.7 +# Use of this source code is governed by a BSD-style license that can be 1.8 +# found in the LICENSE file. 1.9 + 1.10 +""" 1.11 +A clone of 'who' command; print information about users who are 1.12 +currently logged in. 1.13 +""" 1.14 + 1.15 +import sys 1.16 +from datetime import datetime 1.17 + 1.18 +import psutil 1.19 +from psutil._compat import print_ 1.20 + 1.21 + 1.22 +def main(): 1.23 + users = psutil.get_users() 1.24 + for user in users: 1.25 + print_("%-15s %-15s %s (%s)" % \ 1.26 + (user.name, 1.27 + user.terminal or '-', 1.28 + datetime.fromtimestamp(user.started).strftime("%Y-%m-%d %H:%M"), 1.29 + user.host) 1.30 + ) 1.31 + 1.32 +if __name__ == '__main__': 1.33 + main()