Link to home
Start Free TrialLog in
Avatar of Ramu Shetty
Ramu Shetty

asked on

AIX time_last_login script

I need some help in putting a quick script to display Last Login Information of all the users on a AIX server. The format requested is something like below.

----------------------------------------------
User      Gecos       Last Loggedin
----------------------------------------------

User field : User ID
Gecos : User Description
Last Logged in : Readable format

On AIX, I can pull in User field and Gecos from  - awk -F: '{print $1 $5}' /etc/passwd

and Last logged in from  `perl -e 'print scalar localtime(1210762918);'`

How should I put everything together, so that I get an output like

----------------------------------------------
User      Gecos       Last Loggedin
----------------------------------------------

Thanks,


-
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

try this


echo -----------------------------------
usr=`awk -F: '{print $1 $5}' /etc/passwd`
llogin=`perl -e 'print scalar localtime(1210762918);'`
echo "$usr      $llogin"
echo -----------------------------------
Avatar of Ramu Shetty
Ramu Shetty

ASKER

Thanks you....Omar, On the similar grounds, I wrote a script but this is quite not working...

So I have all the users on the system whose UID are starting with "p",

for i in `awk -F: '{print $1}' /etc/passwd | grep ^p`
        do
        x=$i
        y=`lsuser -a time_last_login $i | awk -F'=' '{print $2}'`
        z=`perl -e 'print scalar localtime($y);'`

a=`cat /etc/passwd |awk '{print $5}'`
echo "$x        $a      $z"
done

So I am trying to print out : UserID Gecod Last Login
Can till me what is the output of each command you run in the script?

awk -F: '{print $1}' /etc/passwd | grep ^p

lsuser -a time_last_login $i | awk -F'=' '{print $2}'

perl -e 'print scalar localtime($y);'

cat /etc/passwd |awk '{print $5}'
Here is the info

awk -F: '{print $1}' /etc/passwd | grep ^p
p876km
p515kr
p112qp

lsuser -a time_last_login $i | awk -F'=' '{print $2}'
1412133895
1411394010
1412109891


perl -e 'print scalar localtime($y);'
Wed Dec 31 18:00:00 1969Wed Dec 31 18:00:00 1969Wed Dec 31 18:00:00 1969

cat /etc/passwd |awk '{print $5}'
Paul Ruber
Shawn Zeiler
Mary Kom

I think the perl thing got screwed up,which is to convert the last log to the standard time format
when you run

echo "$x        $a      $z"

What do you get?
So when  I run the Echo command I am getting some undesired output, That is the reason why I approached EE
what do you get?
Not the desired output, a blank screen scrolling with something on the bottom ...
Not the desired output, a blank screen scrolling with something on the bottom ...
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is not working either...here is the output

p876km
Wed Dec 31 18:00:00 1969
<Shawn.M.Zeiler@XXX.com>,#9809TSMTeam@XXX.com:/home/p876km:/usr/bin/ksh
p515kr
Wed Dec 31 18:00:00 1969
<Shawn.M.Zeiler@XXX.com>,#9809TSMTeam@XXX.com:/home/p876km:/usr/bin/ksh
p112qp
Wed Dec 31 18:00:00 1969
<Shawn.M.Zeiler@XXX.com>,#9809TSMTeam@XXX.com:/home/p876km:/usr/bin/ksh


So can you please help me out on this....
The output I am expecting should look like...

----------------------------------------------
User      Gecos       Last Loggedin
----------------------------------------------

User Info can be got from -> awk -F: '{print $1}' /etc/passwd

Gecos can be got from  -> awk -F: '{print $5}' /etc/passwd

Last Loggedin -> perl -e 'print scalar localtime($x);'
Where x=lsuser -a time_last_login UID | awk -F'=' '{print $2}'

Thanks...