The UNIX and Linux Forums  


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
extract x lines after a pattern - place each result in separate file gobi Shell Programming and Scripting 5 06-06-2008 04:03 PM
Separate lines in a single '|' separated line hidnana Shell Programming and Scripting 3 03-17-2008 10:16 AM
If I want to separate my work to child process,what should I do? robocup UNIX for Dummies Questions & Answers 2 08-09-2005 06:14 AM
Monitor does not diplay wajidjafri UNIX for Dummies Questions & Answers 6 06-02-2005 10:06 PM
Does it require each x-client sould run in separate process? ps_sureshreddi UNIX Desktop for Dummies Questions & Answers 0 02-14-2005 03:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-28-2008
mathur mathur is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 7
diplay user process in separate lines

hi
I m trying to display the processes of each user but its coming in one line like

george wilkins
PID TTY TIME CMD 7661 ? 00:00:01 sshd 7662 pts/6 00:00:00 bash
i want the output to be like
PID TTY TIME CMD
7661 ? 00:00:01 sshd
7662 pts/6 00:00:00 bash

my code is

proc=$(users)
for i in $proc
do
echo $(cat /etc/passwd | grep "$i" | cut -d ':' -f 5)
echo $(ps -u $i)
done

any idea how can i make it as a list
thanks

Last edited by mathur; 10-28-2008 at 07:36 AM..
  #2 (permalink)  
Old 10-28-2008
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
for i in `users`
do
cat /etc/passwd | grep \^"$i:" | cut -d ':' -f 5
ps -u $i
done


i.e. Put the output to standard output rather than into a shell variable.
The modified grep gives an exact match on username in the first field in passwd (e.g fred and freddy won't gove false matches).
  #3 (permalink)  
Old 10-28-2008
mathur mathur is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 7
sorry its still not working..My Question is to diplay the processes in line for each user
but its displaying in one line
PID TTY TIME CMD 10886 ? 00:00:00 sshd 10887 pts/3 00:00:00 bash
like this
  #4 (permalink)  
Old 10-28-2008
mathur mathur is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 7
thanks guys i got the soln
echo $(ps –u $i)
to:
echo “$(ps –u $i)”
  #5 (permalink)  
Old 10-28-2008
u4xmnsk u4xmnsk is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 6
Smile Try this !!!

Try this !!!

Code:

who|while read x ;
do
ps -u $x
done

You can also direct each o/p into separate files.
  #6 (permalink)  
Old 10-29-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092

Code:
nawk '{
for(i=1;i<NF/4;i++)
{
	printf $1" "$2" "$3" "$4" "
	for(j=(i*4+1);j<=(i+1)*4;j++)
		printf $j" "
	print ""
}
}' file

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 11:25 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