michael@0: #!/usr/bin/env python michael@0: michael@0: # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: """ michael@0: A clone of 'who' command; print information about users who are michael@0: currently logged in. michael@0: """ michael@0: michael@0: import sys michael@0: from datetime import datetime michael@0: michael@0: import psutil michael@0: from psutil._compat import print_ michael@0: michael@0: michael@0: def main(): michael@0: users = psutil.get_users() michael@0: for user in users: michael@0: print_("%-15s %-15s %s (%s)" % \ michael@0: (user.name, michael@0: user.terminal or '-', michael@0: datetime.fromtimestamp(user.started).strftime("%Y-%m-%d %H:%M"), michael@0: user.host) michael@0: ) michael@0: michael@0: if __name__ == '__main__': michael@0: main()