Displaying the processes of users


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Displaying the processes of users
# 1  
Old 08-18-2006
Outputting the processes of current users to a file

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

Last edited by olimiles; 08-18-2006 at 12:09 PM.. Reason: original title made question look trivial!
# 2  
Old 08-18-2006
Code:
finger | nawk '!/Login/' | while read user name junk
do
    ps -fu $user
done

or
Code:
finger | while read user name junk
do
    [[ $user != Login* ]] && ps -fu $user
done

# 3  
Old 08-18-2006
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

Last edited by olimiles; 08-18-2006 at 04:16 PM.. Reason: worked out how to output results to file :o
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Display info about users (UID GID processes terminal)

I would like to get an opinion for my solution for this task and get feedback about better approach or mistakes I have made. 1. The problem statement, all variables and given/known data: The task is to create a script which prints information about users whose names are specified in the... (2 Replies)
Discussion started by: kornfan
2 Replies

2. UNIX for Dummies Questions & Answers

Denyhosts displaying warning message for users blocked

Hi, I have a dilemma.I am running denyhosts on one of our servers and it monitors illegal ssh/ftp loggins. I am running vsftpd. My manager though has put an additional requirement on me. When someone is blocked my denyhosts he want an error message to be displayed: " YOUR ACCOUNT HAS BEEN... (0 Replies)
Discussion started by: mojoman
0 Replies

3. Shell Programming and Scripting

Sorting the users logged in according to the number of processes

Is it possible to get a list of users sorted by the number of processes executed by each. I have a HP - UX server with 2800 processes running currently. And I want to know the number of processes owned by each person logged in to that server.something like below: user1 : 150 Processes user2 :... (2 Replies)
Discussion started by: engineer
2 Replies

4. Shell Programming and Scripting

How to display what processes, users have opened at a given time

Hello, What i have to do is make a top 10 list of users sorted by the number of processes opened at a given time. Can anyone help me with finding out for a given moment, for all users how many processes each had opened? (5 Replies)
Discussion started by: gabibyte
5 Replies

5. Shell Programming and Scripting

printing each users by processes

hello All, i am trying to get the each users by with thier processing. I have try it in several ways but i am not getting thier my code is #!bin/bash/ users=`cat /etc/passwd | cut -d':' -f5` onlineusers=`users | tr '.' ' '` $onlineusers | while read `$users` do echo `ps -U $users`... (12 Replies)
Discussion started by: sam4now
12 Replies

6. Shell Programming and Scripting

Processes and Users

Thx for all the help so far, I really appreciate it, this is the last task I have to do then I am no longer a trainee ^^, which means I can use whatever utility I want. :O I need to write a script that does more or less what is shown below. The Users Name PID TTY TIME CMD 12345 pts/3... (22 Replies)
Discussion started by: barbus
22 Replies

7. UNIX for Dummies Questions & Answers

displaying the users

how can i list the users( and only those users) who logged in more than once? thanks in advance... (1 Reply)
Discussion started by: needyourhelp
1 Replies

8. UNIX for Dummies Questions & Answers

users and there processes

I am trying to write a script to list all users and their processes. I cant seem to find out how to link the PID to the user. For example if i run ps -a I get a nice list of all the processes running and their PID, but no information about which user is running them. I need the users real name not... (3 Replies)
Discussion started by: iago
3 Replies

9. Shell Programming and Scripting

i need a scipt to email users with idle processes!?

hello, i am VERY new to this whole script world. I need to come up with a script that will email a user if they have an idle process past 500 minutes...any suggestions??? Thanks so much. (0 Replies)
Discussion started by: sheppy28
0 Replies

10. UNIX for Dummies Questions & Answers

Users and processes

Hi All, I am trying to write a script to list all users and their processes. I cant seem to find out how to link the PID to the user. For example if i run ps -a I get a nice list of all the processes running and their PID, but no information about which user is running them. If i use w i... (17 Replies)
Discussion started by: Chiefos
17 Replies
Login or Register to Ask a Question