System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How to find users who didn't logging from the last 60 days

 
Highlighted
Frequent Advisor

How to find users who didn't logging from the last 60 days

Hi

I want to find users who didn't logging from the last 60 days.

for i in `awk -F: '$3 > 100 { print $1 }' /etc/passwd`
do last $i | head -1 done
With the above script it want find the users who didn't logging even once. It is showing blank.

Thanks
Manish
4 REPLIES 4
Highlighted
Honored Contributor

Re: How to find users who didn't logging from the last 60 days

]# date --date "60 days ago"
Thu Apr 26 22:33:37 EDT 2007
]# last|grep kumarts
kumarts pts/1 hcj-60762b23.noa Mon Jun 25 22:31 still logged in
kumarts pts/0 hcj-60762b23.noa Mon Jun 25 22:17 still logged in
kumarts pts/0 hcm-25122c0e.noa Sun Jun 24 11:09 - 21:03 (09:54)
kumarts pts/0 mas-5828e2cd.noa Sun Jun 24 09:59 - 11:05 (01:06)
kumarts pts/0 bpt-d33c3932.noa Sat Jun 23 21:33 - 01:19 (03:45)
kumarts pts/1 hsl-582f0205.noa Tue Jun 19 21:17 - 23:09 (01:51)
kumarts pts/0 adq-e43b9ed5.noa Mon Jun 18 20:18 - 08:27 (12:08)
kumarts pts/0 asc-587c2d96.noa Tue Jun 12 22:40 - 08:36 (09:56)
kumarts pts/1 adc-41e47d2e.noa Tue Jun 12 09:17 - 17:40 (08:22)
kumarts pts/0 adc-41e47d2e.noa Tue Jun 12 09:15 - 17:51 (08:35)
kumarts pts/0 kjw-25134059.noa Thu Jun 7 22:06 - 07:20 (09:14)
kumarts pts/0 adc-41e47d2e.noa Mon Jun 4 08:55 - 18:16 (09:21)
kumarts pts/0 rfp-587c2faf.noa Sat Jun 2 11:59 - 02:33 (1+14:33)

Do a test loop/comaprison between those outputs. If you find a newer entry on second output than the first output , the match fails.....
Highlighted
Esteemed Contributor

Re: How to find users who didn't logging from the last 60 days

Ineligant, I suppose, but something like this should work (though you'll have to play with this to make it work across years)

#!/bin/bash
lim=`date --date "60 days ago" +%m%d`

for user in `awk -F: '$3 > 100 {print $1}' /etc/passwd` ; do
test_date=`last -R -1 $user|grep -v wtmp|cut -c27-32`
if [ -z "${test_date}" ]
then
echo "$user never logged in"
else
test_mon=`echo "$test_date"|awk '{print $1}'`
test_day=`echo "$test_date"|awk '{print $2}'`
test "$test_day" -lt 10 && test_day="0"${test_day}
case "${test_mon}" in
Jan) test_mon="01" ;;
Feb) test_mon="02" ;;
Mar) test_mon="03" ;;
Apr) test_mon="04" ;;
May) test_mon="05" ;;
Jun) test_mon="06" ;;
Jul) test_mon="07" ;;
Aug) test_mon="08" ;;
Sep) test_mon="09" ;;
Oct) test_mon="10" ;;
Nov) test_mon="11" ;;
Dec) test_mon="12" ;;
esac
test "${test_mon}${test_day}" -gt $lim || echo "$user ${test_mon}${test_day}"
fi
done
Highlighted
Trusted Contributor

Re: How to find users who didn't logging from the last 60 days

Hi Manish,

Use date --date "60 days ago"

Thanks & Regrads
Reshma
Highlighted
Frequent Advisor

Re: How to find users who didn't logging from the last 60 days

Thanks a lot for your support.