Solved

script to print all users looged in the system and their processes, should display real name on the top then their processes, for each user.

Posted on 2007-12-04
8
261 Views
Last Modified: 2008-02-01
Hi
Wanted to write a shell script which should display all users logged in and the current processess they are running, it should display thier real name first then their processess...then the next users name and processess...so on..
thanks
dileep Pattattu
0
Comment
Question by:dileeppattat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 20403194
Hi,

Try

for user in `who | awk '{print $1}'`
do
echo ----------------
finger omar | head -1 | awk -F":" '{print $3}'
echo "login name: $user"
ps -u $user
echo ----------------
done
0
 

Author Comment

by:dileeppattat
ID: 20403602
hi
sorry that didnt help, I want to print the real name of the user not the login name, eg. dileep.pattattu is my login name bu the real name is Dileep Pattattu. Could you tell me how to obtain the a list of all users logged in and their processes please. the actual output of the shell should be as follows
Dileep Pattattu
PID TTY TIME CMD
31799 pts/3 00:00:00 bash
31866 pts/3 00:00:00 bash
2495 pts/7 00:00:00 vim
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps

Sonia Arnold
PID TTY TIME CMD
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps

thanks
Dileep
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20403629
Hi,

This is the out put of

finger omar | head -1 | awk -F":" '{print $3}'

If you do not want login name then remove the line

echo "login name: $user"

So the script will be


for user in `who | awk '{print $1}'`
do
echo ----------------
finger omar | head -1 | awk -F":" '{print $3}'
ps -u $user
echo ----------------
done
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 20403651
Sorry, I was testing with my ysername :)

The script is

for user in `who | awk '{print $1}'`
do
echo ----------------
finger $user | head -1 | awk -F":" '{print $3}'
ps -u $user
echo ----------------
done
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20405223
Using finger is not a reliable way of extracting the username.  For example, if you have two users called

freds - Fred Smith
johnf - John Freds

Then

finger freds

will display both users.

Better to use

grep "^$user:" /etc/passwd |cut -f5 -d:
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20405226
Obviously, my above comment isn't relevant if the users are stored in NIS or LDAP.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20405249
If you do want to use finger, it's best to use:

finger -fsm $user | awk '{print $2}'

if your version of finger has the -f and -s flags, otherwise


finger -m $user | head -1 | awk -F: '{print $NF}'

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20405292
Thank you Tintin for your valuable input :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question