The script I have is outputting $1 the most often logged users in the past $2 days
#var[$i]=$(awk -F: '{print $5}' /etc/passwd);
last -s -$2days | awk '{users[$1]++} END{for(i in users){print users[i], i}}' | sort -r | head -$1 | awk '{print $2 " -- " $1}';
so the output is following:
username -- (amount of logins)
But I'm trying to get an output with first and last name from /etc/passwd so it's:
first and last name, username -- (amount of logins)
But every idea I try to come up with doesn't seem to work for me. I tried looping the awk with /etc/passwd and then using -v in another awk or trying to get the output of 2nd awk into an array and then comparing it with /etc/passwd but I couldn't make either work. Does anyone have an idea how to handle this?
This should let you start:
first and last name, username -- (amount of logins)
fromlast
commandlast
command by adding some required optionssort
andhead
are omitted, I believe you can handle it