I have searched on internet many script to have account with last connection date to check out for those with more than 3 months in my servers. But I have many Unix (Solaris , HP UX, AIX ) It was very difficult to make one script for all because some command like "lastlog" on Linux daesn't exist on UNIX. So I have taken pieces of script around the internet and I have modified them to work on multiple platform. It is not really achived but it can help many administrator. Below 4 scripts:
AIX:
SOLARIS:
HP-UX
For Linux server is merely simple just enter:
AIX:
##################################### # Orphans Account ##################################### PASSWORD_FILE="/etc/passwd" print "User |Account Locked |Time since last login | User Info " for LoginID in in $(cat $PASSWORD_FILE | cut -f1 -d:) do # see if the account is locked account_locked=$( awk 'BEGIN{ FS = ""; RS = ""}$1 == "'"$LoginID"':"{if (match($0,/account_locked /) ){print substr($0, RSTART+17, 5)} }' /etc/security/user ) # find the secs since the epoch in seconds for the last login time time_last_login_secs=$( awk 'BEGIN{ FS = ""; RS = ""}$1 == "'"$LoginID"':"{if (match($0,/time_last_login = [0-9]+/) ){print substr($0, RSTART+18, 10)} }' /etc/security/lastlog ) # find the secs since the epoch in seconds for the last unsuccessful login time
SOLARIS:
#!/usr/bin/ksh while read LINE;do # extract usernames and home directories from /etc/passwd USER=$(echo $LINE|awk -F: '{print $1}') HOMEDIR=$(echo $LINE|awk -F: '{print $6}') # extract login info from finger using grep LAST_LOGIN=$(finger -l ${USER}|egrep "Never logged in.|Last login") echo "$USER | $HOMEDIR | $LAST_LOGIN" done < /etc/passwd exit
HP-UX
#!/usr/bin/ksh while read LINE;do # extract usernames and home directories from /etc/passwd USER=$(echo $LINE|awk -F: '{print $1}') HOMEDIR=$(echo $LINE|awk -F: '{print $6}') # extract login info from finger using grep LAST_LOGIN=$(finger ${USER}|grep -E 'Last login|Never logged') echo "$USER | $HOMEDIR
For Linux server is merely simple just enter:
lastlog
All comments will be greatly appreciable!
ReplyDelete