1843946 Members
2282 Online
110226 Solutions
New Discussion

Script for Dormant Users

 
SOLVED
Go to solution
nibble
Super Advisor

Script for Dormant Users

guys, i need a script that will do the following:

run the script on that day and it will generate the list of users who have not logon for the last n days (n maybe 30, 60)

ive tried last, comm with /etc/passwd but its so general for the Month only and doesnt care of the Year.

i wonder if there are ways to calculate the last 30 days of todays date...then filtering em out login details..

tnx..
10 REPLIES 10
Keith Bryson
Honored Contributor

Re: Script for Dormant Users

You're right about last (and finger for that matter). The only thing I can suggest is looking at the timestamp on the users .sh_history file in their home directory (if they have one!). Hope it helps, guess someone else will have a better idea.

Keith
Arse-cover at all costs
Keith Bryson
Honored Contributor

Re: Script for Dormant Users

You may want to try this if your users have the .sh_history file:

for user in `ls -1 /home | grep -v "lost+found"`
do
if [ `find /home/$user -name .sh_history -mtime -30 | wc -l` = 1 ]
then
echo "User $user has logged in during the last 30 days"
else
echo "User $user has NOT logged in during the last 30 days"
fi
done

All the best - Keith
Arse-cover at all costs
nibble
Super Advisor

Re: Script for Dormant Users

hi kelly,
actually, ive done it via finger -sw, redirecting the output to a file, then manually sorting it out (whew!). now, i really wonder how can it be improved considering that i have about 5000 users per server.

im thinking of the date... can we manipulate the date command (or its output) so that we could have it deducted for n days? all i viewed is the formatting output, w/c if ur goin to do it mathematically (date - 30), obviously gives the wrong value considering that day is not in decimal.

i wonder if theres a script that could calculate current date minus n_dates..

nibble
Super Advisor

Re: Script for Dormant Users

that's a nice way of checking it out K, but cant be applied since my users are in once generic home directory and dont have any history files. so i could only rely to finger or last
Timo Ruiter
Advisor

Re: Script for Dormant Users

Hello nibble,

The solution with a find on the .sh_history file can still work if you change the name of the history file to include the userid, like:

export HISTFILE=~/histories/.sh_hist.$LOGNAME

to keep history files small use

export HISTSIZE=100

This means you will collect some 5000 history files in the 'histories' directory, but that should not be a problem.

HTH
Timo
Confucius say: he who runs through forrest in straight line will hit tree
Stephen Keane
Honored Contributor

Re: Script for Dormant Users

If you have perl installed you could use the following to print the date 30 days ago. (Note 86400 is the number of seconds in a day)

# perl -e 'print scalar localtime(time - (30 * 86400))'


Peter Godron
Honored Contributor
Solution

Re: Script for Dormant Users

Hi,
attached my script:
I have tested it on one of our servers and it works!
Regards
Peter Godron
Honored Contributor

Re: Script for Dormant Users

Nibble,
have you had a look at my script?
IS this problem still open, or can the thread be closed?
Regards
Rick Garland
Honored Contributor

Re: Script for Dormant Users

Using the 'finger' command is a good isea, unless you have security concerns and have the 'finger' turned off.

I use the 'last' command and it variations. I keep a wtmp file for some 90 days, if a user does not show up in the last output then I know that user has not logged in for the last 90 days.


nibble
Super Advisor

Re: Script for Dormant Users

tnx everyone...the script helped a lot. i think il hav it modify to fit my requirement.

we may close this thread now.

matsalams!