The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
printing each users by processes sam4now Shell Programming and Scripting 12 04-28-2008 06:11 PM
Processes and Users barbus Shell Programming and Scripting 22 10-03-2007 07:09 PM
displaying the users needyourhelp UNIX for Dummies Questions & Answers 1 09-13-2007 01:37 AM
users and there processes iago UNIX for Dummies Questions & Answers 3 09-10-2007 02:51 PM
Users and processes Chiefos UNIX for Dummies Questions & Answers 17 06-17-2006 04:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-18-2006
olimiles olimiles is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 18
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 11:09 AM.. Reason: original title made question look trivial!
  #2 (permalink)  
Old 08-18-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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 (permalink)  
Old 08-18-2006
olimiles olimiles is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 18
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 03:16 PM.. Reason: worked out how to output results to file :o
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0