Solved

AIX time_last_login script

Posted on 2014-09-30
12
1,300 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Ramu Shetty
Comment Utility
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
Comment Utility
when you run

echo "$x        $a      $z"

What do you get?
0
 

Author Comment

by:Ramu Shetty
Comment Utility
So when  I run the Echo command I am getting some undesired output, That is the reason why I approached EE
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
what do you get?
0
 

Author Comment

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

Author Comment

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

Accepted Solution

by:
omarfarid earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
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.:
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now