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
259 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…

808 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