list last

🧩 Syntax:
(USE_COLUMN=1;COLUMN_JSON=;USE_COLOR=1;e=echo g=grep c=date x=cut p=cat dt="$(last -1|tail -n 1|awk '{$2=$1="";print $0}'|$c -d "$($p)" +%Y-%m-%d)";dt="$(last -Fiws "$dt"|grep -m1 system|awk '{$4=$3=$2=$1="";print $0}'|rev|cut -d \  -f 3-|tr -s [:blank:]|rev|{ $p;$e "$dt";}|head -n 1|$c -d "$($p)" +%s|$c -d "@$(($($p)+1))" +%Y-%m-%d\ %H:%M:%S)" a="$(last -Fiws "$dt")";$e "$a"|cut -d \  -f 1|sort -u|$g -v ^$|while read -r i;do $e "$a"|$g -m1 "^$i .*still logged in"||{ $e "$a"|$g -m1 "^$i";};done|$g -v wtmp\ begins|awk '{$2=$3=$4="";print $0}'|tr -s [:blank:] \ |sed -E 's/^([^ ]*) ([^-]*) -[^(]*/\1\t\2\t/;s/^([^ ]*)(.*) (still logged in)/\1\t\2\t(alive)/'|while read -r i;do u="$($e "$i"|$x -f 1)";d=$(($($c +%s)-$($c -d "$($e "$i"|$x -f 2)" +%s)));l="$($e "$i"|$x -f 3|tail -c +2|head -c -2)";printf '%s\t%s\t%s\n' "$u" "$($e "$(($d/86400))d $(($d/3600-($d/86400)*86400/3600))h $((($d/60)%60))m $((d%60))s")" "$l";done|{ a=$($p);$e "$a"|$g alive;$e "$a"|$g -v alive;}|{ [ -n "$USE_COLUMN" ]&&column -t -s "$(printf \\t)" -N "username,time since last login,last login duration" ${COLUMN_JSON:+-J}||cat;}|{ c=${USE_COLOR:+sed '/alive["},]*$/s/.*/\x1b[32;1m&\x1b[0m/;/00:0[0-4]["},]*$/s/.*/\x1b[34m&\x1b[0m/'};${c:-$p};})