I have lots of home directories under /ifshome on Linux. I want to see which users have not logged in for the past 6 months, and my solution is to parse the /ifshome/user/.lastlogin file. Each .lastlogin file has the same format, 1 line:
Last Login: Fri Mar 09 18:06:27 PST 2001
I need to build a shell script that can parse the .lastlogin file in each user’s home directory and output those directories whose owners haven’t logged in for the last 6 months.
Ok, here is my silly way (untested!) using a pure shell script parsing your file.
The
datecommand can parse a date string, and output the seconds since 1970. Subtract them from the current seconds, and divide by the amount of seconds one month takes. Print that value together with the users path.Sort the output using
sort -nand pipe that intolessthen you can browse the list of users and their activity.For a non-hackish way, consider Juan’s lastlog idea. It’s on my linux too.