############################################ # Program 6 # by Gary C. Miller, 11/28/07 # ############################################ # # The command: ps -ef list all processes # The command: sed 's/ *//' removes the leading spaces # The command: cut '-d ' -f1 cuts out the first field # The command: sort -u does a unique sort # The command: grep -v UID allows for everything except for UID # The command: wc -l counts the number of lines # echo -n "Number of Users: " ps -ef | sed 's/ *//' | cut '-d ' -f1 | sort -u | grep -v UID | wc -l cnt=0 userlist="" for user in `ps -ef | sed 's/ *//' | cut '-d ' -f1 | sort -u | grep -v UID` ; do cnt=`expr $cnt + 1` if [ $cnt -eq 1 ] ; then userlist="$user" else userlist="${userlist}, $user" fi done echo "User Names: $userlist" # # For each user # totalnbrprocesses=0 for user in `ps -ef | sed 's/ *//' | cut '-d ' -f1 | sort -u | grep -v UID` ; do echo "*********************" echo "User: $user" nbrprocesses=`ps -u $user | grep -v PID | wc -l` echo "Number of Processes: $nbrprocesses" totalnbrprocesses=`expr $totalnbrprocesses + $nbrprocesses` processlist="" cnt=0 for process in `ps -u $user -o args | grep -v COMMAND` ; do cnt=`expr $cnt + 1` if [ $cnt -eq 1 ] ; then processlist="$process" else processlist="${processlist}, $process" fi done echo "Process List: $processlist" done echo "*********************" echo "Total Number of User Processes: $totalnbrprocesses"