Sponsored Content
Full Discussion: To learn last login date
Top Forums Shell Programming and Scripting To learn last login date Post 302961060 by MadeInGermany on Monday 23rd of November 2015 12:00:28 PM
Old 11-23-2015
SysV Unix does not store the year in wtmp.
Most if not all Unix vendors have migrated to own extended wtmp files, named wtmpx or wtmps.
When adapting the last command, some vendors added new non-standard options.
Here is a portable script that makes some guesses and tries to compute the missing year:
Code:
last | PATH=/usr/xpg4/bin:/bin:/usr/bin awk '
BEGIN {
m["Jan"]=1
m["Feb"]=2
m["Mar"]=3
m["Apr"]=4
m["May"]=5
m["Jun"]=6
m["Jul"]=7
m["Aug"]=8
m["Sep"]=9
m["Oct"]=10
m["Nov"]=11
m["Dec"]=12
}
{
for (i=4;i<NF;i++) {
  if (($(i-1) in m) && $i~/^[0-9]?[0-9]$/ && $(i+1)~/^[0-9]/) {
    if ((m[$(i-1)]>pm || m[$(i-1)]==pm && $i>pday) && NR>1) year--
    pm=m[$(i-1)]; pday=$i
    $i=$i " " year
    break
  }
}
print
}' year=`date +%Y`

This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to display last login date/time?

I was wondering if anyone had a script that would display the last time a user logged into a particular machine. I know about the "last" command, but it gives too much info.... I just wanted to know the last time a user used his/her id. ANy help would be greatly appreciated. Ryan (3 Replies)
Discussion started by: ryaneverett5
3 Replies

2. UNIX for Dummies Questions & Answers

Collecting & Displaying of Last User ID and Date of Last Login

Hi, I needed to write a script to "Collect and Display the Last User ID and Date of Last Login". The requirement is: When a workstation stops reporting it could be for many reasons. If we know the last person who logged in before the workstation came down, then we can contact the last... (1 Reply)
Discussion started by: amittal
1 Replies

3. Shell Programming and Scripting

Collecting & Displaying of Last User ID and Date of Last Login

Hi, I needed to write a script to "Collect and Display the Last User ID and Date of Last Login". The requirement is: When a workstation stops reporting it could be for many reasons. If we know the last person who logged in before the workstation came down, then we can contact the last... (1 Reply)
Discussion started by: amittal
1 Replies

4. UNIX for Dummies Questions & Answers

Last user login date

I have been asked to create a report of when users last logged into an AIX box. Upon login, this information appears to be available but I have not located it yet. Any help? Thanks! (2 Replies)
Discussion started by: JTeter
2 Replies

5. UNIX for Dummies Questions & Answers

last login date and time for all users

I need a command that will list all the users and their last login date & time. I was trying the last command and the who command, but can't get exactly what I need. I just need the output to be user name and last login date . Thanks for your help! (3 Replies)
Discussion started by: igidttam
3 Replies

6. Web Development

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both,... (2 Replies)
Discussion started by: WhotheWhat
2 Replies

7. UNIX for Dummies Questions & Answers

script to write the last login date and time

I want to make a script to write me in a file the date(format 16-12-2008) and hour(format 15:12:21) of the last login in the system; what can i add to the <last> command in order to be suitable? (4 Replies)
Discussion started by: kalimat
4 Replies

8. UNIX for Dummies Questions & Answers

How to do a login time and date list of users never logged on?

Hello, I'm trying to do a list of user that never connected to a couple of servers. I want to do a diff between the servers lists, and print out only the users that never has logged on each server. Here my first step : SERVER01: # finger `egrep -v -e "^\s*#" /etc/passwd | awk '{ print $1 }' |... (4 Replies)
Discussion started by: gogol_bordello
4 Replies

9. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

10. UNIX for Dummies Questions & Answers

Last login date

i need to know, for all users in /etc/passwords, when their last login was including the year. is this kept as one record per person anywhere? I believe that WTMPX, keeps transactions of login and logout, but i just need the last time including people who never have logged in. i know that... (2 Replies)
Discussion started by: neil lehrer
2 Replies
sttime(3)						    ShapeTools Toolkit Library							 sttime(3)

NAME
stMktime, stWriteTime - date and time handling SYNOPSIS
#include <config.h> #include <sttk.h.h> time_tstMktime (char *string); char*stWriteTime (time_t date); DESCRIPTION
stMktime scans the given string and tries to read a date and time from it. It understands various formats of date strings. The following is a list of all valid formats, optional parts in brackets. [Tue] Jan 5[,] [19]93 This includes the standard asctime(3) format. Jan 5 With no year given, the year defaults to the current year. [19]93/01/05 This notation requires month and day represented by exactly two digits. 5.1.[19]93 This is the usual German notation. 5.1. German notation referencing the current year. A certain time, given together with the date must always have the following form. hours:minutes[:seconds] Each of the fields must be an integer value within the proper range (hours: 0-23, minutes and seconds: 0-59). Values below 10 may be written as one digit numbers. The time value may be placed anywhere in the date string: at the beginning, at the end, or somewhere in the middle. Any amount of white- space may be given between a field of the time value and the separating colon. The time is always considered to be local time. stWriteTime generates a time string similar to asctime(3) from its date argument. SEE ALSO
asctime(3) BUGS
Time Zone Names within the time string (like `MET') are not handled properly. In most cases they will cause a failure. sttk-1.7 Thu Jun 24 17:43:35 1993 sttime(3)
All times are GMT -4. The time now is 10:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy