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
users and there processes iago UNIX for Dummies Questions & Answers 3 09-10-2007 02:51 PM
i need a scipt to email users with idle processes!? sheppy28 Shell Programming and Scripting 0 02-02-2007 04:08 PM
Displaying the processes of users olimiles Shell Programming and Scripting 2 08-18-2006 02:57 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 10-03-2007
barbus barbus is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
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 00:00:00 vim

The Users2 Name2
PID TTY TIME CMD
12345 pts/2 00:00:00 vim

Print out all users currently logged on to the system and display the processes they are running.
The problem I am facing is I don’t know how to acquire the users name (the actual name not the Username), as for the format it has to be like shown above more or less.

And again I cant use SED or Awk (I will be free to use them after am done with this ).

So its gona be one of those while read line statements.
So the 1 million dollar question is how I format it by field

Will the cut command help me at all here?

I am starting to think this guy uses Google to find the tasks that he wants me to do, This is unbelievably similar to what i want to do , maybe it is just an exercise that is given to most beginners or something.

Thanks in advanced for any help.
  #2 (permalink)  
Old 10-03-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by barbus
The problem I am facing is I don’t know how to acquire the users name (the actual name not the Username), as for the format it has to be like shown above more or less.
Check '/etc/passwd' file for the mapping...
  #3 (permalink)  
Old 10-03-2007
barbus barbus is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
that did the trick thx, now i guess i must link the the user IDs to the name some how
  #4 (permalink)  
Old 10-03-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
#!/bin/ksh

userID='uucp'

while IFS=: read userIDpasswd junk junk junk userName junk
do
   if [ "${userID}" = "${userIDpasswd}" ]; then
      echo "userID->[${userID}] userName->[${userName}]"
   fi;
done < /etc/passwd
  #5 (permalink)  
Old 10-03-2007
barbus barbus is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
cool, thx man

I have a question though, this programme will be ran by a few people, if one of those people where to change a process name or amend a users name, will this outcome be effected?
  #6 (permalink)  
Old 10-03-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by barbus View Post
cool, thx man

I have a question though, this programme will be ran by a few people, if one of those people where to change a process name or amend a users name, will this outcome be effected?
you'll need write a 'generic' script and pass the user ID to the script as a parameter. The process name(s) will be listed by whatever tool you use all the processes.
The snippet of the code provided above deals only with the userID->userName mapping - not with the listing of processes.
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 08:13 PM.


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