May 2017
Beginner
552 pages
28h 47m
English
The active_users.sh script reads from /var/log/wtmp or a wtmp log file defined on the command line. The last -f command extracts the log file contents. The first column in the log file is the username. The cut command extracts the first column from the log file. The sort and uniq commands reduce this to a list of unique users.
The script's outer loop iterates through the users. For each user, grep is used to extract the log lines corresponding to a particular user.
The last column of each line is the duration of this login session. These values are summed in the inner while read t loop.
The session duration is formatted as (HOUR:SEC). This value is extracted with awk to report the last field and then piped to tr -d to remove ...