Another script.

This script will get list all processes affliated to a given user. Better than ps and can specify processes per user :)

#!/usr/bin/python
#adminscript.py
import pwd
from subprocess import *
import pwd
a = Popen(["ps", "axo", "euid"], stdout=PIPE, stderr=PIPE)
output = a.communicate()
uid_list = output[0]
error_list = output[1]
for uid in uid_list.split('n')[1:-1]:
    uid1 = int(uid)
    user_list = pwd.getpwuid(uid1)[0]
    print user_list
    full_name_list = pwd.getpwuid(uid1)[4]
    for user in user_list:
        b = "ps"
        c = "au" + user
        process = Popen([b, c], stdout=PIPE, stderr=PIPE)
        output2 = process.communicate()
        list_of_processes = output2[0]
        list_of_errors = output2[1]
        print user + list_of_processes

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment