Re: Need script to extract from /etc/security/lastlog -> list of users and their la
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Re: Need script to extract from /etc/security/lastlog -> list of users and their la




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: Need script to extract from /etc/security/lastlog -> list of users and their la  
Henry


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-20-04 01:47 AM

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]+/) ){pri
nt
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/lastlo
g )
# 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.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:06 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register