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.
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?
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:
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.