Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, i've got a script here which lists the processes of each logged on user, beginning with the user's real name.
The problem i'm having is that when it gets to the ps command, i get an error
"ps: error: User name does not exist"
though it then outputs each user's processes like it should.finger | while read user name junk
do
[[ user != Login* ]] && ps -fu $user
doneCan anyone tell me why it's not working properly?
Many thanks in advance
Oliver

You forgot the dollar sign, $, on $user:
finger | while read user name junk
do
[[ $user != Login* ]] && ps -fu $user
done

Thanks Nails!
But although the error has now been corrected. i still don't get the User's name above their list of processes! What have i missed?
I'm trying to get an output similar to this:Mark Thomas
PID TTY TIME CMD
31799 pts/3 00:00:00 vimTom Jones
PID TTY TIME CMD
31854 pts/5 00:00:00 psMany thanks in advance
Oliver

You are only printing the contents of the ps -fu command for the user. Of course, the ps command isn't the most portable of commands, but I think you have to explictly code for the name. You can do something like this:
finger | while read user fn ln junk
do
[[ $user != Login* ]] && echo " $fn $ln"; ps -fu $user
doneIn the above script, I'm assuming that the second and third fields of finger's output will always be the first and last name of the user. This can readily be a bad assumption.
At least on my Solaris system, the 'Name' delivered by the finger command is the comment field of the etc/passwd file - which can be anything.
Have you considered printing out /etc/passwd's comment field? Then, you don't have to worry about parsing finger's output:
This is my take:
finger | while read user fn ln junk
do
if [[ $user != Login* ]]
then
awk ' BEGIN { FS=":" }
{
if($1 == v1)
{
# print the user name for the correct user
printf(" %s\n", $5)
exit
}
} ' v1="$user" /etc/passwd
ps -fu $user
fi
done

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |