Something like this small scriptingWhat is a good way to identify "dormant" accounts?Code:#!/bin/sh # # A small script to list a users last login # it will list every user in the /home directory with # last login exceeding one month # for d in `ls /home/` ; do LOGIN=`last $d | head -n 1 | grep -v "still logged in" \ | awk '{print $3 " " $ 4 " " $5}'` if [ "$LOGIN"x != x ]; then case $LOGIN in " ") ;; *) # we're dealing with a valid user who isnt online at the moment # calculate how many month it's been since last login OLD_DATE=`date -d "$LOGIN" +%Y%m%d` NEW_DATE=`date +%Y%m%d` DIFF=`echo "$NEW_DATE-$OLD_DATE"| bc` if [ $DIFF -ge 100 ]; then # display users with more than 1 month stale login MONTH=`echo "$DIFF/100" | bc` DAYS=`echo "$DIFF%100" | bc` echo -n "User $d was last logged in $MONTH month" if [ $DAYS -ge 1 ]; then echo -n " and $DAYS day" if [ $DAYS -ge 2 ]; then echo -n "s" fi fi echo " ago" fi ;; esac fi done


Reply With Quote

Bookmarks