[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
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
Medium Priority
?
267 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
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…

649 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