Solved

AIX time_last_login script

Posted on 2014-09-30
12
1,589 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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…

734 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