want to find the users who have not logged in from past 60 days - aix
This is a discussion on want to find the users who have not logged in from past 60 days - aix ; Hi, Would like to write a script to find the users who have not logged in from the past 60 days.. We have AIX 5.3........ any inputs plz? Thanks...
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| Would like to write a script to find the users who have not logged in from the past 60 days.. We have AIX 5.3........ any inputs plz? Thanks |
|
#2
| |||
| |||
|
rak пишет: > Hi, > > Would like to write a script to find the users who have not logged in > from the past 60 days.. We have AIX 5.3........ any inputs plz? Thanks AIX it's powerful OS. ![]() You can find information about last login on file `/etc/security/lastlog' For example: admin: time_last_login = 1226593857 tty_last_login = /dev/pts/0 host_last_login = admin.office unsuccessful_login_count = 0 -- UV-RIPE |
|
#3
| |||
| |||
|
On Nov 13, 9:12*am, Vladimir Usenko > rak пишет: > > > Hi, > > > Would like to write a script to find the users who have not logged in > > from the past 60 days.. We have AIX 5.3........ any inputs plz? Thanks > > * AIX it's powerful OS. ![]() > * You can find information about last login on file `/etc/security/lastlog' > > * For example: > > admin: > * * * * *time_last_login = 1226593857 > * * * * *tty_last_login = /dev/pts/0 > * * * * *host_last_login = admin.office > * * * * *unsuccessful_login_count = 0 > > -- > UV-RIPE is there any ready-made script or any ideas in writing such? |
|
#4
| |||
| |||
|
On Nov 13, 6:41 pm, rak > On Nov 13, 9:12 am, Vladimir Usenko > > > > > rak пишет: > > > > Hi, > > > > Would like to write a script to find the users who have not logged in > > > from the past 60 days.. We have AIX 5.3........ any inputs plz? Thanks > > > AIX it's powerful OS. ![]() > > You can find information about last login on file `/etc/security/lastlog' > > > For example: > > > admin: > > time_last_login = 1226593857 > > tty_last_login = /dev/pts/0 > > host_last_login = admin.office > > unsuccessful_login_count = 0 > > > -- > > UV-RIPE > > is there any ready-made script or any ideas in writing such? lsuser -a id ALL | awk '{ print $(NF-1) }' |\ while read user ; do lssec -f /etc/security/lastlog -s "$user" -a time_last_login done man lsuser man lssec hth Hajo |
|
#5
| |||
| |||
|
On Nov 13, 10:13*am, Hajo Ehlers > On Nov 13, 6:41 pm, rak > > > > > > > On Nov 13, 9:12 am, Vladimir Usenko > > > > rak пишет: > > > > > Hi, > > > > > Would like to write a script to find the users who have not logged in > > > > from the past 60 days.. We have AIX 5.3........ any inputs plz? Thanks > > > > * AIX it's powerful OS. ![]() > > > * You can find information about last login on file `/etc/security/lastlog' > > > > * For example: > > > > admin: > > > * * * * *time_last_login = 1226593857 > > > * * * * *tty_last_login = /dev/pts/0 > > > * * * * *host_last_login = admin.office > > > * * * * *unsuccessful_login_count = 0 > > > > -- > > > UV-RIPE > > > is there any ready-made script or any ideas in writing such? > > *lsuser -a id *ALL | awk '{ print $(NF-1) }' |\ > * while read user ; do > * * *lssec -f /etc/security/lastlog -s "$user" -a time_last_login > * done > > man lsuser > man lssec > > hth > Hajo- Hide quoted text - > > - Show quoted text - I got this script, which looks good #!/usr/bin/ksh #set -x #Try this script. #It will check and lock the accounts automatically for those logins that #have not been used to s set number of days. expdays=90 #<< ---- Set number of days in past here! let expiry=86400*$expdays locked=" " tmp1=/tmp/exp.tmp1.$$ tmp2=/tmp/exp.tmp2.$$ tmp2a=/tmp/exp.tmp2a.$$ tmp3=/tmp/exp.tmp3.$$ tmp4=/tmp/exp.tmp4.$$ # List all users that are allowed to login lsuser -a login account_locked time_last_login ALL |grep -Ev ^"root| daemon|bin|sys|adm|nobody" | grep "login=true" > $tmp1 # get all users who have logged in at least once with login date grep 'time_last_login' $tmp1 | sed -e 's/login=true //' -e 's/ account_locked=//' -e 's/time_last_login=//' >$tmp2 # get all users who have not logged in since creation grep -v 'time_last_login' $tmp1 | sed -e 's/login=true //' -e 's/ account_locked=//' >$tmp2a # get today's date in seconds from epoch for comparison year=`date +%Y` day=`date +%j` hour=`date +%H` minute=`date +%M` let today="($year - 1970) * 365 * 86400 + ($day - 1) * 86400 + $hour * 3600 + $minute * 60 + ($year - 1969) / 4 * 86400" # for each user found, check whether has not been unused too long cat $tmp2 |while read user locked last do let min=$today-$expiry if [[ $min -gt $last ]] then let login="($today - $last) / 86400" echo $user':'$login':'$locked >> $tmp4 #chuser shell='/usr/local/bin/locked' #account_locked='true' $user fi done any comments?? |
|
#6
| |||
| |||
|
day= now=$( date +%s ) # Number since epoch expired=$(($now-86400*$days)) |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
All times are GMT -4. The time now is 03:18 AM.





Linear Mode