HOWTO: List Inactive Users PDF Print E-mail
User Rating: / 11
PoorBest 
Written by Michael Felt   

Listing Inactive Users

I wanted an easy way to list inactive users (defined as users who had not logged in). I had a solution using perl, but I decided not to use it - because perl might not be installed.

So, I wrote a simplier script using ksh. The example here does have some extra text that I'll probably put behind a verbose flag so I can just create a list of user accounts I want to lock.

Read more for inactive.ksh

#!/usr/bin/ksh
# inactive.ksh
# list users that have not logged on within $1 days, or 60 by default
# also report users with no history of a login that are not locked

## Author: Michael Felt
## Copyright 2009 rootvg.net

now=`date +%s`
days=$1
if [[ $days -le 0 ]]
then
days=60
fi

delta=$(($days*86400))
refpoint=$(($now - $delta))

print The current date and time is: `date`
print "Inactive users (no login) for at least $days days are:"

lsuser -a time_last_login ALL |
grep -e time_last_login |
while read line
   do
        set $line
        username=$1
        logintime=`echo $2 | awk -F= ' { print $2 } '`
        if [[ $logintime -lt $refpoint ]]; then
                print $username
        fi
   done

print The following users have no last_login recorded and are unlocked
lsuser -a time_last_login account_locked ALL | grep -v time_last_login |
grep false |
while read line
   do
         print $line
   done

 
< Prev   Next >
Login