Normally I can detect user's last logon time if last return anything via below function. My question is : if last doesn't return anything then I want to look in the user's home directory date and time for the most recently modified file.
lastlogLatest() {
last -n 1 "${userName}" | awk ' {
for( i=1;i<=NF;i++ ) {
if ( $i ~ /Mon|Tue|Wed|Thu|Fri|Sat|Sun/ ) {
j = 0
str = ""
for ( j=i; j<=NF;j++ ) {
str = ( str ? (str FS $j):$j )
}
print str
break
}
}
}'
}