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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |