|
| sorry about CRLF's
#####################################
# Check for valid user #
#####################################
echo ""
echo "Enter UNIX User ID to display : \c"
read LoginID
if [ "${LoginID}" = "" ]
then
echo " ERROR invalid input"
exit 1
fi
if ! lsuser $LoginID > /dev/null 2>&1
then
echo "ERROR $LoginID not a valid UNIX User ID"
exit 1
fi
# see if the account is locked
account_locked=$( awk 'BEGIN{ FS = "\n"; 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 = "\n"; 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
time_last_unsuccessful_login_secs=$( awk 'BEGIN{ FS = "\n"; RS = ""}$1
== "'"$LoginID"':"{if (match($0,/time_last_unsuccessful_login =
[0-9]+/) ){print substr($0, RSTART+31, 10)} }' /etc/security/lastlog )
# user PERL to get the dates
time_last_login=$( /usr/local/bin/perl -le 'print scalar
localtime(shift)' $time_last_login_secs )
time_last_unsuccessful_login=$( /usr/local/bin/perl -le 'print scalar
localtime(shift)' $time_last_unsuccessful_login_secs )
# get the number of unsuccessful logins
#num_unsuccessful_logins=$( awk 'BEGIN{ FS = "\n"; RS = ""}$1 ==
"'"$LoginID"':" {if (match($0,/unsuccessful_login_count = [0-9]+/)
){print substr($0, RSTART+27, 1)} }' /etc/security/lastlog)
num_unsuccessful_logins=$( awk '$1 == "'"$LoginID"':",/^$/ {if
(/unsuccessful_login_count/) {print $3}}' /etc/security/lastlog )
# show the users name
user_info=$(awk -F: '$1 == "'"$LoginID"'" {print $5}' /etc/passwd )
# show the users home directory
home_dir=$(awk -F: '$1 == "'"$LoginID"'" {print $6}' /etc/passwd )
# show the users home UNIX id
user_id=$(awk -F: '$1 == "'"$LoginID"'" {print $3}' /etc/passwd )
#lsuser -a account_locked unsuccessful_login_count gecos home id
${LoginID}
print "Account Locked =" $account_locked "\nTime since last login ="
$time_last_login "\nTime since last unsuccessful login ="
$time_last_unsuccessful_login "\nNumber of unsuccessful logins ="
$num_unsuccessful_logins "\nUser Info =" $user_info "\nUsers home
directory =" $home_dir "\nUsers UNIX id =" $user_id
Tom Brehony wrote:
> The subject lines says it all. I am looking for a script (ideally
Korn
> Shell)
> to extract from /etc/security/lastlog a list of users and their last
login
> time
> in human readable format.
>
> I have seen PERL scripts to convert the Unix time in seconds to a
human
> readable form, but I do not have PERL installed on the AIX 4.2 box
> I am using and I am not familiar with PERL anyway and would not be
> able to modify the script to do what I need.
>
> Anyone have something that will do this?
>
> Tom.
|
|