1829578 Members
5071 Online
109992 Solutions
New Discussion

Re: Dormant Users

 
SOLVED
Go to solution
Vipulinux
Respected Contributor

Dormant Users

Hi
Need a shell script that can tell the users who have not logged into the box since X no. of days eg 90 days ..

Need to work on login and last command

Cheers
Vipul
7 REPLIES 7
Ivan Ferreira
Honored Contributor

Re: Dormant Users

Try something like this (I have not tested):

# Not logged in days
NOT_LOGGED_DAYS=90

# Get NOT_LOGGED_SEC seconds

NOT_LOGGED_SEC=`date --date "$NOT_LOGGED_IN days ago" +%s`

# Last logged

LAST_LOGGED=`date --date "$(last -1 $1 | grep -v begins | awk '{ print $4,$5 }')" +%s`

if [ $LAST_LOGGED -lt NOT_LOGGED_SEC ]; then
echo "The user $1 did not logged in $NOT_LOGGED_DAYS days"
else
echo "This user is not a dormitant user"
fi

Usage:

script_name username
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Vipulinux
Respected Contributor

Re: Dormant Users

Hi Ivan

Thanks for your response.
I dont want to do it one by one.
I need a script that compares /etc/passwd and logins output and shows those users who have not logged in since 90 days..
Thanks
Rick Garland
Honored Contributor
Solution

Re: Dormant Users

Here is a perl script that will list the 'last' info for all users. From this list you can decipher who has/has not logged in for last 90 days.

You could pipe this output through sort, or include the perl code to sort, to get your requested info.

Vipulinux
Respected Contributor

Re: Dormant Users

Hi Rick

The script is great!!!
just wonder if it could show the year of login as well i.e whether it was 2005 or 2006

Human Nature: Always demanding!!
Cheers
Rick Garland
Honored Contributor

Re: Dormant Users

last does not display the year so some sort of rotation scheme (of the wtmp file) is necessary to prevent the overlap of months
Vipulinux
Respected Contributor

Re: Dormant Users

Thanks for the replies!!
Vipulinux
Respected Contributor

Re: Dormant Users

Hi All

there is 1 script but doesnt seem to give corret results..
is there a script that give full details of users who have'nt logged in since x no of days and also when was there last login etc..


cheers