Solved

AIX time_last_login script

Posted on 2014-09-30
12
1,504 Views
Last Modified: 2014-10-07
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,


-
0
Comment
Question by:Ramu Shetty
  • 7
  • 5
12 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 40353891
try this


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

Author Comment

by:Ramu Shetty
ID: 40353893
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
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 40353898
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}'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Ramu Shetty
ID: 40353908
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
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 40353967
when you run

echo "$x        $a      $z"

What do you get?
0
 

Author Comment

by:Ramu Shetty
ID: 40354421
So when  I run the Echo command I am getting some undesired output, That is the reason why I approached EE
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 40355418
what do you get?
0
 

Author Comment

by:Ramu Shetty
ID: 40355574
Not the desired output, a blank screen scrolling with something on the bottom ...
0
 

Author Comment

by:Ramu Shetty
ID: 40355597
Not the desired output, a blank screen scrolling with something on the bottom ...
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 40356260
ok, please run below and see what output you get

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

Author Comment

by:Ramu Shetty
ID: 40358678
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....
0
 

Author Comment

by:Ramu Shetty
ID: 40358683
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...
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
incorrect file reading in bash 7 143
Remote install of MSI file 4 53
How do disable only TLSv1.0 in Oracle Sun One 7.1 Server 9 128
while read ID; do 4 53
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question