See last login datetimes on a SunOS server
# cat userlist.sh
# This must be run as root
# Name of the server to be prepended to each line?
SERVER=R17-PRMY
# Nothing user-editable below
NOW=`date '+%Y%m%d'`
FILENAME=users_CMS-$SERVER-$NOW.txt
# Create or Empty the file
> $FILENAME
# Just using Finger doesn't list this much information
for user in $(sort /etc/passwd | cut -f1 -d":"); do
line=$( \
finger -s -m -f $user | \
awk '{print "%% " $0 "\n"}' | \
sed -e "s/%%/$SERVER/g" | \
tr -s '\n' \
);
echo "$line" >> $FILENAME;
done
Gives output like below. Notice the completely different dates based on last (or no) login.
R17-PRMY cms CMS pts/19 35d Mon 03:39 1.2.3.4
R17-PRMY cmssvc Services pts/64 <Nov 11 00:36> 5.6.7.8
R17-PRMY cmst ??? < . . . . >