![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| logged out users | roshni | Post Here to Contact Site Administrators and Moderators | 1 | 07-06-2007 12:02 AM |
| how many users logged | trichyselva | Shell Programming and Scripting | 4 | 05-05-2006 11:17 PM |
| Users logged in through which NIC | cburtgo | IP Networking | 5 | 04-28-2006 03:59 PM |
| All tcp/ip users are logged out | Docboyeee | IP Networking | 2 | 03-13-2003 10:07 AM |
| Information about users who have logged. | rooh | UNIX for Dummies Questions & Answers | 2 | 12-26-2001 03:42 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
loop through logged on users or file?
Hi
I’m trying to loop through all logged on users and get their real names So I came up with this script but it doesn’t work Who > userList #save logged on users to temp file while read username #loop through file do awk '{ print $1 }' | grep /etc/passwd | cut -d: -f5 done < userList # awk '{ print $1 }' | grep /etc/passwd | cut -d: -f5 basically gets the login name from each line in userList and gets the real name from the matching line in /etc/passwd but this doesn’t work Can someone please direct me to the right way of doing this? I’m using bash shell |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
The finger command will give you real name..
man finger |
|
#3
|
|||
|
|||
|
Re: Loop
Thanks, but how do I loop through each logged on users and extract their real names?
|
|
#4
|
||||
|
||||
|
Code:
#!/bin/ksh
who | while read user junk
do
nawk -F: -v user="${user}" '$1 == user { print $5; exit }'
done
|
|
#5
|
|||
|
|||
|
Code:
#!/bin/ksh
who | while read user junk
do
realname=`grep $user /etc/passwd | awk ' { FS=":"; print $5}'`
print "User Id - $user and real name - $realname. \n"
done
|
|
#6
|
||||
|
||||
|
Quote:
Last edited by vgersh99; 06-19-2006 at 11:25 AM. |
|
#7
|
|||
|
|||
|
Thanks, this worked for me:
who | while read user junk do realname=`grep $user /etc/passwd | cut -d: -f5` echo "User Id = $user and real name - $realname. \n" done |
|||
| Google The UNIX and Linux Forums |