Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. #!/bin/sh
  2. #shell script which reads n users and print the name,the number of proc and the last command
  3. echo give  the number of users
  4. read nr
  5. echo give $nr users
  6. i=0
  7. while [ $i -lt $nr ];
  8. do
  9.    read x
  10.    #prints the name from /etc/passwd, we make x a var for awk
  11.    awk -F: -v user="$x" '$1==user {print $5}' /etc/passwd
  12.     # -o user prints only the user column,
  13.     # sort sorts in alphabetical order, so uniq can count each
  14.    ps hax -o user | sort | uniq -c|  grep $x| awk '{print $1}'
  15.    ps -aux| awk -v user="$x" '$1==user {print $11}'|tail -1
  16.   #colom 11 is the current command,tail -1 the last line
  17.    i=$((i+1))
  18.  
  19. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement