Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AIX time_last_login script

Posted on 2014-09-30
12
Medium Priority
?
1,749 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

660 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