I want to write a script for login statistics. I want to count how many times a user logged in, and then display them in ascending, or descending order, given by the end user. The problme being, i don't know how to write a script that could count how many times a user logged in. I have to use the last command.
#!/bin/bash userlist=$(cat /etc/passwd | cut -d : -f 1) for user in $userlist; do timesloggedin=$(last $user | head -n -2 | wc -l); echo $timesloggedin $user; done | sort -r
This gets the name of ALL the users on the system, including daemon accounts etc.
If you don't want that, supply
userlist with a list of your usernames.
To get the output in ascending order, drop the
-r flag to sort.