Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #shell script which reads n users and print the name,the number of proc and the last command
- echo give the number of users
- read nr
- echo give $nr users
- i=0
- while [ $i -lt $nr ];
- do
- read x
- #prints the name from /etc/passwd, we make x a var for awk
- awk -F: -v user="$x" '$1==user {print $5}' /etc/passwd
- # -o user prints only the user column,
- # sort sorts in alphabetical order, so uniq can count each
- ps hax -o user | sort | uniq -c| grep $x| awk '{print $1}'
- ps -aux| awk -v user="$x" '$1==user {print $11}'|tail -1
- #colom 11 is the current command,tail -1 the last line
- i=$((i+1))
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement