- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- User last successful login
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 07:30 PM
10-25-2004 07:30 PM
Is there any way or script to get all the users last successful login & pipe to a text file?
Example the data captured is:
peter|24Oct2004
andrew|16Oct2004
regards.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 07:39 PM
10-25-2004 07:39 PM
Re: User last successful login
just use > after the command you used to get the data captured.
Your question is a bit vague.
You can use cut or awk with field separator | to single out fields.
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 07:40 PM
10-25-2004 07:40 PM
Re: User last successful login
You could use the last command.
e.g.
for i in $(cat /etc/passwd | awk -F: '( $3 > 100 ) { print $1 } ')
do
last -1 $i | awk '{ print $1"|"$5,$4 }'
done
Regards,
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 07:51 PM
10-25-2004 07:51 PM
Re: User last successful login
you can use the "last" command which gives you your desired output
only last will give you the successful logins of all users
if you use last
You can customize the output using awk
eg
last
lastb would be the contrary (unsuccessful logins) btw
Regards
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 07:51 PM
10-25-2004 07:51 PM
Re: User last successful login
Parsing it with perl like this :
$ll="";
open(STDIN,"last|sort -k 1|");
while (
chomp;
$cl=$_;
($user,@rest)=split / */,$cl;
($luser,@rest)=split / */,$ll;
if ($user eq $luser) {
$ll=$cl;
} else {
print "$ll\n";
$ll=$cl;
}
}
print "$cl\n";
will give you last line for each user. Modify it to get the output you want.
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 09:31 PM
10-25-2004 09:31 PM
Re: User last successful login
What I want is to get the LATEST last login for each users. Example andrew has login to server in July and Aug, then the script will only retrieve a line of user id & the month is Aug. (No duplicated)
Any idea?
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 09:39 PM
10-25-2004 09:39 PM
Re: User last successful login
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 09:42 PM
10-25-2004 09:42 PM
Re: User last successful login
last -1 username
check my previouse post, may be it has some errors but it does a grep on user stings in the passwd file, ( only users >100 as uid) and issue a last -1 on that user. Redirection to a file .. done >>file
Regards,
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 10:23 PM
10-25-2004 10:23 PM
Re: User last successful login
Gideon
Your script is running but how to sort by alphabetical and display the year login? Beside that, why there is only "|" appears?
Output:
ehg|18 Oct
hamdanar|26 Oct
lkf|26 Oct
ckkhoo|26 Oct
leg|26 Oct
|
wtmp|8 Oct
|
wtmp|8 Oct
hcwong|26 Oct
|
wtmp|8 Oct
vasus|23 Sep
|
Fred
There is some errors when I am running your script.
Error:
# sh user.sh
user.sh: =: not found.
user.sh[2]: Syntax error at line 2 : `(' is not expected.
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 10:54 PM
10-25-2004 10:54 PM
Re: User last successful login
In order to sort, use the sort command
...
done | sort >>file
Why the only the "|" appears.. this can be the case when the user never logged in.
you can solv this by
..
done | grep -v ^| sort >>file
Regards,
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 11:09 PM
10-25-2004 11:09 PM
Re: User last successful login
It prompts me this error when I added the line that you proposed
# sh user.sh
grep: illegal option -- ^
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]-f pattern_file...[file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]
Btw, is it able to show the year login as well?
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2004 11:17 PM
10-25-2004 11:17 PM
Re: User last successful login
done | grep -v "^|" | sort >> file
As far as i know last does not print a year.
HTH,
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2004 12:02 AM
10-26-2004 12:02 AM
Re: User last successful login
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2004 12:26 AM
10-26-2004 12:26 AM
Re: User last successful login
'one liner' in perl:
last | perl -e 'while(<>){($u,$x,$x,$m,$d)=split; $all{$u}="$m $d" unless ($all{$u})} foreach (sort keys %all) {print "$_|$all{$_}\n" if ($_)}'
- loop through input
- split by whitespace, remembering user, month, day
- remember date for user unless that user has a day already
- when all input processed, report on all remembered users, sorted.
no, I do not knwo how a year change looks like. But a perl script like above is readily expanded to have a rolling months window where every month in this year prints the current year, and every 'future' month prints the last year.
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2004 01:02 AM
10-26-2004 01:02 AM
Re: User last successful login
for user in `listusers | awk '{ print $1 }'`
do
last -1 $user | awk '{ print $1"|"$5$4 }'
done
We can not get year informations from last output there.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2004 01:07 AM
10-26-2004 01:07 AM
Re: User last successful login
# for user in `logins -u | awk '{ print $1 }'`
do
last -1 $user | grep -v '^wtmp begins' | awk '{ printf $1"|"$5$4;system("date +'%Y'") }'
done
Some user will not contain login details. That will show as wtmp begin.. information with log there.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2004 01:22 AM
10-26-2004 01:22 AM
SolutionI needed a coffee break.. below a potential solution with year handling. It compares todays month and day ($M, $D) with the one in the last record ($m, $d) and adjust the year if deemed in the past.
test.p:
($x,$x,$x,$D,$M,$Y)=localtime;
while(<>){
($u,$x,$x,$m,$d)=split;
next if ($all{$u});
$y = $Y + 1900;
$i = index("JanFebMarAprMayJunJulAugSepOctNovDec",$m)/3;
next if ($i < 0);
$y-- if ($i > $M);
$y-- if ($i == $M && $d > $D);
$all{$u}="|$m $d $y";
}
foreach (sort keys %all) {
print "$_$all{$_}\n" if ($_);
}
Usage:
last | perl test.p
Cheers,
Hein.