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
250 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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
Comment Utility
Obviously, my above comment isn't relevant if the users are stored in NIS or LDAP.
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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
Comment Utility
Thank you Tintin for your valuable input :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now