Hi Guys, I'm trying to identify the last logins by all the users in the system in AIX. the last command gives me the output, but there is no year displayed for it . Since there is a duplication of months i mean Apr 2010 and Apr 2009 also its giving me inaccurate data.. Is there a way I can filter out the entries only for 2010.
one solution is you mention the date from which you want to see who's logged in: the -t option of last command.
last -t 20100101010101
-t will only give you the users who were logged into the system at that particular time. It wont give you the logs after that for ex... bash-3.00# last -t 201001010001 root pts/3 sa2sscp027 Dec 30 21:11 - 21:26 (43+00:15) root pts/1 sa2sscp027 Dec 30 17:11 - 21:26 (43+04:15) The above tells me only the users who were on the system at 1st Jan 2010 00:01 hrs
If you feel comfortable with C code, you could try compiling something like this. It works on my Linux box, but I have no idea if it will work on AIX.
#include <stdio.h>
#include <utmp.h>
#include <string.h>
#include <time.h>
int main(void) {
struct utmp *line;
time_t timestamp;
utmpname("/var/log/wtmp");
setutent();
while( (line = getutent()) != NULL) {
if (line->ut_type == USER_PROCESS ) {
timestamp = line->ut_tv.tv_sec;
printf("%s %s", line->ut_user, asctime(localtime(×tamp)));
}
}
endutent();
return 0;
}
There certainly would be a way to do this with perl, or any other systems programming language too.
I compile like this
$ gcc -Wall source.c -o progname
THx Guys,
In the mean time I have written one script which will give me the users last login in the system ( All users )
# !/usr/bin/bash
ssh unadm@$1 ' lsuser -a time_last_login ALL | sed 's/\ time_last_login=/:/g' > /userlogins
cat userlogins | grep : > temp | awk -F":" '{print $2}' temp | xargs -I {} perl -le "print scalar localtime ({})" > temp1
awk -F":" '{print $1}' temp > temp2
paste temp2 temp1
rm temp temp1 temp2
In the above I want to execute the first line command highlighted below as root using sudo..
ssh unadm@$1 ' lsuser -a time_last_login ALL | sed 's/\ time_last_login=/:/g' > /userlogins
Can anyone explain how can i use sudo in this remote command
---------- Post updated 06-17-10 at 12:30 AM ---------- Previous update was 06-16-10 at 07:50 PM ----------
Its done Well guys
# !/usr/bin/bash
if [ $# -eq 1 ]
then
echo "IPADDRESS : $1"
ssh unadm@$1 ' echo "HOSTNAME: $(hostname) \t DATE: $(date)"'
ssh unadm@$1 "sudo lsuser -a time_last_login ALL | sed 's/\ time_last_login=/:/g'" > userlogins
cat userlogins | grep : > temp; awk -F":" '{print $2}' temp | xargs -I {} perl -le "print scalar localtime ({})" > temp1
awk -F":" '{print $1}' temp > temp2
paste temp2 temp1 | awk -F" " '{ printf "%-20s %s %s %-2d %s %d\n", $1, $2, $3, $4, $5, $6 }'
rm temp temp1 temp2
exit
else
echo "USAGE: $0 <IPADDRESS>"
exit 1
fi
bash-3.00$
Output as below:p
HOSTNAME: test1 DATE: Thu Jun 17 00:11:13 CDT 2010
root Thu Jul 24 05:02:01 2008
testuser Sun Jan 25 12:49:22 2009
mqm Tue Sep 9 04:23:46 2008
db2inst1 Sat Sep 12 00:38:38 2009
jrnj0i0 Mon Apr 13 05:51:25 2009
prp0i0 Mon Sep 7 00:24:04 2009