Hi guys,
I'm writing a script to display all the current logged on users and the processes they're running, output to a file. The output will look similar to this:
User1 (Real name not login name)
PID TTY TIME CMD
3179 pts/3 00:00:00 vim
User2
PID TTY TIME CMD
....etc
The users should not be displayed more than once.
So far i've got:
USERS=`finger | awk '{print $1 "\t" $2 "\n"}'`
I figure i'll use
ps -u username
but how do i take the username from $USER and apply it to the ps?
Any help greatly appreciated, as i'm just starting out with UNIX!
Thanks in advance,
Oliver
finger | nawk '!/Login/' | while read user name junk
do
ps -fu $user
done
or
finger | while read user name junk
do
[[ $user != Login* ]] && ps -fu $user
done
Thanks tmarikle!
There is 1 problem for each code you gave me:
1st code:
I get a 'nawk does not exist' error, changing it to awk works but i'm thinking that the nawk adds the users name above each entry?
2nd code:
the ps gets an error that the User name does not exist, but the rest still runs and i get the details i need, though again without the User's name at the top of each entry!
Also, is there an easier way to change which columns are output ie just the PID, TTY, Time and CMD or should i just stick to formatting the results after they're put into the file?
Thanks again, it's much appreciated and i'm still learning!
Oliver