We have moved to www.dataGenX.net, Keep Learning with us.

Friday, March 08, 2013

Count User logins in Nix


This script will count the User logins on the Server and if you pass the username to script, It will fetch the last login details of the user.





#!/bin/ksh
if [[ "$1" != "" ]]; then ##logins of user $1 only
last "$1"
exit
fi
##----------------------- else count all logins:
echo " --- counting all logins and sorting ..."
last | awk '{print $1}' | sort | uniq -c | sort -nr
last wtmp ## to see since when
echo ""
echo " --- To see logins of a user, enter username : [ Use Ctrl-C to quit] "
read -r name
if [[ "$name" != "" ]]; then
last "$name"
fi
view raw count_last.sh hosted with ❤ by GitHub