![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
||||
|
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. |
|
||||
|
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
|
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|