The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
logged out users roshni Post Here to Contact Site Administrators and Moderators 1 07-06-2007 04:02 AM
HP-UX users get logged off while idle. Laoinjo UNIX for Advanced & Expert Users 5 06-04-2007 12:28 PM
how many users logged trichyselva Shell Programming and Scripting 4 05-06-2006 03:17 AM
Users logged in through which NIC cburtgo IP Networking 5 04-28-2006 07:59 PM
All tcp/ip users are logged out Docboyeee IP Networking 2 03-13-2003 01:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-26-2006
kungfuice kungfuice is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
Trying to get list of logged on users sorted

I'm trying to execute a single shell command that will give me a sorted list of all the users currently logged into the system, displaying the users name as it appears in /etc/passwd.

I've tried


Code:
awk -F: '{print $1}' /etc/passwd | xargs finger -s | cut -c11-28 | uniq

This list whoever does not give me the current logged in users, since if I run who the list is much smaller.

Can anyone help me out, and give me some guidance here?
  #2 (permalink)  
Old 07-26-2006
xinusys xinusys is offline
Registered User
  
 

Join Date: May 2006
Posts: 13
Smile Hi!

Kindly use the command "users" and sort it with the help of pipe.

Cheers.
  #3 (permalink)  
Old 07-26-2006
kungfuice kungfuice is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
That works to give me a list of usernames, but what I'm looking for is the users real names, sorted.

I have tried using


Code:
users | xargs grep /etc/passwd | cut -d: -f5 | sort -fd | uniq

But that does not work either since grep seems to try and execute the usernames instead of looking for them in the /etc/passwd file.
  #4 (permalink)  
Old 07-26-2006
mph mph is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 58
I know it's not pretty but


Code:
usrs=`users | sort`
for i in `echo $usrs`
do
grep $i /etc/passwd | awk -F \: '{print $1}'
done

should work.
  #5 (permalink)  
Old 07-26-2006
kungfuice kungfuice is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
That didn't really do what I wanted but I've modified it to give me the Real names at least, the problem still being that this list is not sorted, and this has to be executed from a command line.

I'm really lost here guys any help?


Code:
usrs=`who | cut -d" " -f1 | sort -df | uniq`
for i in $usrs
do
  grep $i /etc/passwd | awk -F \: '{print $5}'
done

  #6 (permalink)  
Old 07-26-2006
mph mph is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 58
it is sorted by user name not by real name. Put the sorting code in after you get the real names.

Try something like this:


Code:
if [ -f tmp.txt ]
then
  rm -f tmp.txt
fi
usrs=`users`
for i in $usrs
do
  grep $i /etc/passwd | awk -F \: '{print $5}' >> tmp.txt
done
sort tmp.txt 
rm tmp.txt

Again it's not pretty but it should work and sort by real name.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0