[Solved] Using w; how to list find all the users


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Using w; how to list find all the users
# 1  
Old 11-12-2012
[Solved] Using w; how to list find all the users

Hi,

On my system, I have about 75 users. Some uers have two or three sessions on the same systems. when I do w, it shows all the sessions. Is there any way to find only the users and not worry about how many sessions. For example: you can see sshe has four connection. I only want to know the users. From the results below, I am looking for
sak, apr, sshe, xzha, peter. I tried doing w |grep -v but not working.


Code:
w |more
 16:06:52 up 568 days, 21:26, 75 users,  load average: 0.07, 0.10, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
sak pts/1    :37.0            21Feb12 263days  0.18s  0.18s -csh
apr pts/3    -                Tue18    4days  0.07s  0.07s -bin/tcsh
sshe  pts/4    -                18Oct12 25days  0.00s  7:34  kdeinit: kded 
xzha   pts/6    -                Fri17    0.00s  0.69s  0.58s -bin/tcsh
xzha   pts/7    -                Wed10    5days  0.00s 10.63s kdeinit: kded 
peter    pts/9    :24.0            13:45    2:20m 52.80s  0.09s -csh
sshe  pts/12   -                19Oct12 24days  0.15s  0.03s -bin/tcsh
sshe  pts/13   -                19Oct12 24days  0.00s  7:39  kdeinit: kded 
sshe  pts/15   -                19Oct12 24da


Last edited by Scott; 11-12-2012 at 06:21 PM.. Reason: Code tags, not ICode tags...
# 2  
Old 11-12-2012
Code:
w | awk '!/PCPU/ && !/days/ { print $1 } ' | sort -u

This User Gave Thanks to Yoda For This Post:
# 3  
Old 11-13-2012
awesome... bipinajith. awk works great.
# 4  
Old 11-13-2012
Quote:
Originally Posted by samnyc
Code:
w |more
 16:06:52 up 568 days, 21:26, 75 users,  load average: 0.07, 0.10, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
sak pts/1    :37.0            21Feb12 263days  0.18s  0.18s -csh
apr pts/3    -                Tue18    4days  0.07s  0.07s -bin/tcsh
sshe  pts/4    -                18Oct12 25days  0.00s  7:34  kdeinit: kded 
xzha   pts/6    -                Fri17    0.00s  0.69s  0.58s -bin/tcsh
xzha   pts/7    -                Wed10    5days  0.00s 10.63s kdeinit: kded 
peter    pts/9    :24.0            13:45    2:20m 52.80s  0.09s -csh
sshe  pts/12   -                19Oct12 24days  0.15s  0.03s -bin/tcsh
sshe  pts/13   -                19Oct12 24days  0.00s  7:39  kdeinit: kded 
sshe  pts/15   -                19Oct12 24da

Quote:
Originally Posted by bipinajith
Code:
w | awk '!/PCPU/ && !/days/ { print $1 } ' | sort -u

That's not a reliable approach. If all of a user's sessions have been idle for a while, they will not be listed because !/days/ would exclude them all. The same condition will also exclude any sessions currently running a command line which includes "days". Any username in which the string "days" appears is also similarly doomed.

Similar issues apply to the use of !/PCPU/.

In my opinion, a much more robust solution would specifically exclude the header:
Code:
w | awk 'NR>2 {print $1} | sort -u

Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
# 5  
Old 11-13-2012
If you don't care about sorting :
Code:
w | awk 'NR>2&&!a[$1]++{print $1}'

or
Code:
w | awk '{NF=1}NR>2&&!a[$1]++'

This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 11-14-2012
List of unique users:
Code:
who -u | awk '{print $1}' | sort | uniq

This User Gave Thanks to methyl For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List the Manager of Users in AD - Using list- Get-ADuser

Is there any command that can used in Linux that export usernames and their manager's name from AD using bash shell script? I know this can be done using powershell but I need to use Linux for this procedure. (2 Replies)
Discussion started by: dellanicholson
2 Replies

2. UNIX for Advanced & Expert Users

Find the list of files with a set of Users

Hello all, I want to find the files for certain users. I cant make the or condition work in this instance. I've tried the code below but it didnt worked. Any input on how to get the list for all files for this users. find . -type f -user abc134 -o -user xyz345 -o bce483 -exec ls... (6 Replies)
Discussion started by: sethmj
6 Replies

3. UNIX for Dummies Questions & Answers

Users list

Hi i would like to know were the folder that contain file with list of all users ? And were i can learn about what kind of folder i have and wheat they have inside? question 2. when i write ls -a i see all directories and then i choose for example Documents and inside Documents i typed again... (1 Reply)
Discussion started by: iliya24
1 Replies

4. Shell Programming and Scripting

[solved] Problem with find

hi All, I am using the command find /home/mqm/check/ -mtime +1|wc -l to get a count of the files older than a day under the check directory. But instead of getting the count of the files under check directory I m getting a count including the check directory itself. Can someone please tell... (0 Replies)
Discussion started by: jayii
0 Replies

5. UNIX for Advanced & Expert Users

[Solved] mpathadm list lu no output

When I try to configure my HBA ports on Solaris 10; I cant see any output. bash-3.2# mpathadm list lu bash-3.2# I checked /kernel/drv/fp.conf file. ... mpxio-disable="no"; ... What shall I check more? what shall I do? ---------- Post updated at 10:18 AM ---------- Previous update was... (0 Replies)
Discussion started by: hubatuwang
0 Replies

6. UNIX for Advanced & Expert Users

list of users

Hello!Does anybody know how to solve this script: ,,write a shell script which displays a list of names of users who have created files "*. c" in the last day."? (1 Reply)
Discussion started by: theodoraa
1 Replies

7. Shell Programming and Scripting

Find Usage solved

How can I find the biggest file in a branch? I tried find / \*.\* | xargs du | sort -n 1,1 | head 1 but shell do nothings :( ---------- Post updated at 03:07 PM ---------- Previous update was at 02:41 PM ---------- Solved: find / -name \*.\* | xargs du | sort -nr | head -n 1 (0 Replies)
Discussion started by: Guccio
0 Replies

8. UNIX for Dummies Questions & Answers

How do i find out the list of users whose terminal is writable?

Hello, i just wanted to know how do i find out the list of users whose terminal is writable?i mean i used who -T but this gives a list of all users whose terminal is writable or blocked and not writable. So how do i do this?I am new to Unix. (2 Replies)
Discussion started by: salman4u
2 Replies

9. UNIX for Dummies Questions & Answers

Find users using system(List them only once)

Hey, got a few questions here for anyone who can help...... Command line to - display users using the system, but count them only once. Command line to - use the lastcomm command to display how many times ive used grep in october. Command line to - list all logged on users with at least 6... (3 Replies)
Discussion started by: xBuRnTx
3 Replies

10. UNIX for Dummies Questions & Answers

su - user... how to find out the list of users and their passwords..

hi, to do a su - user, we need to know what are the users... so in unix 1) which file to see the list of users, passwords? (2 Replies)
Discussion started by: yls177
2 Replies
Login or Register to Ask a Question