LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2006, 06:05 PM   #1
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Rep: Reputation: 15
Listing users and processes.


Hi,

Is there a way to display users logged on and there processes on one print rather than using "ps -a" and "finger" and then merging the relavent fields with AWK?

Cheers

Mike
 
Old 06-07-2006, 07:02 PM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
Run 'w'. Does it display what you want?

-twantrd
 
Old 06-07-2006, 11:20 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
Never mind.
 
Old 06-08-2006, 03:39 AM   #4
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by osor
Never mind.
Uhh?

Do you have any idea if this is possible?
 
Old 06-08-2006, 03:47 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
I suggest using "w" or "who" rather than "finger".
ie
Code:
who -up
 
Old 06-08-2006, 03:54 AM   #6
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by timmeke
I suggest using "w" or "who" rather than "finger".
ie
Code:
who -up

Nice one, thanks. Will check once I get home.

Mike
 
Old 06-08-2006, 05:47 PM   #7
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Hi again,

I can't seem to use the who -p option on my shell but I have found that if I type "ps -U" username then it lists the processes for that user, so If I can somehow extract the user names from who and then send then to "ps -U" one at a time then I should be okay, only trouble is I can't work out how to do it, it won't let me pipe the info.

Any ideas?

Cheers

mike
 
Old 06-08-2006, 06:29 PM   #8
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Hi,

I think I have it sorted, I need to find out how to make awk print " quotations marks, i tried preceding them with a backslash but it dont work, does anyone if its possible?

Mike

EDIT its okay, i got it sorted without them

I needed to write a program which displayed users and there processes plus there TTY and time and came up with this :

Code:
#!/bin/sh
finger > myfile
awk '{print $1, $2, $3}' myfile |
sed -e 's/Login Name Tty//g' |
awk '{print "echo " $2, $3} {print "ps -U ",$1} ' |
sed -e '1s/echo//g;2s/ps -U//g' > myfile
sh myfile
this works fine I now get

Code:
michael kelly
  PID TTY          TIME CMD
22339 ?        00:00:01 sshd
22340 pts/1    00:00:00 bash
30515 pts/1    00:00:00 sh
30521 pts/1    00:00:00 sh
30522 pts/1    00:00:00 ps
[michael.kelly@unix michael.kelly]$
What do you reckon? any ways I might look to improve it? I dont need the seconds sed commadn if I can stop awk's print method planting an extra echo and ps -U at the top of my script with no arguments beside them. I get an error but the rest of the scripts run so I ahev included the seconds sed to delete the lines before I call "sh" to execute.




Mike

Last edited by mike9287; 06-08-2006 at 07:01 PM.
 
Old 06-09-2006, 02:57 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
A hint:
the problem you describe lies in the fact that the first line printed by "finger" is just a column header.
So, modify your first awk to disregard this header row and you should be fine.

Code:
awk '{print $1, $2, $3}' myfile |
thus should be replaced by:
Code:
awk {if (NR>1) print $1, $2, $3}' myfile |
or something like that.
 
Old 06-09-2006, 03:12 AM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Not sure what your EXACT intention is, but ...

Code:
ps -au | grep `who|cut -d" " -f1`
[edit]
OK, that was daft; doesn't work if there's more than
one user logged in :} ... I'll think some more.
[/edit]

Ok, that works :}
[edit2]
Code:
ps -au|egrep `who|awk '{printf $1"|"}END{print""}'|sed 's/|$//g'`
[/edit2]


Cheers,
Tink

Last edited by Tinkster; 06-09-2006 at 03:22 AM.
 
Old 06-09-2006, 03:14 AM   #11
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by timmeke
A hint:
the problem you describe lies in the fact that the first line printed by "finger" is just a column header.
So, modify your first awk to disregard this header row and you should be fine.

Code:
awk '{print $1, $2, $3}' myfile |
thus should be replaced by:
Code:
awk {if (NR>1) print $1, $2, $3}' myfile |
or something like that.
Thanks, that sound good and will half the length of my script with adding 3 characters.

That also conculdes the course work I have to do so I won't be bothering you anymore (at least not for a while). I must say a big thank you to everyone who helped.

Thanks m8

Mike
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get a listing of running daemons / processes greengrocer Linux - Newbie 6 08-28-2005 04:36 PM
Listing users not in GUI Darklight451 Linux - General 3 11-23-2004 09:35 AM
Listing Processes oriel_gizmo Programming 6 08-20-2004 06:40 AM
Listing processes by memory usage? Seventh Linux - Newbie 3 06-17-2004 11:05 AM
listing users... spotass Linux - Newbie 1 06-12-2004 03:18 AM


All times are GMT -5. The time now is 11:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration