Need "year" value of user's last login


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need "year" value of user's last login
# 1  
Old 07-28-2009
Need "year" value of user's last login

Hello,

We have a requirement of finding which users logged into a UNIX (Solaris) box and how many times they logged in so far and their last login.

I used "last" command in my script and got everything fine but not able to capture the "year" of date/time of the users' login. Looks like "last" command doesn't display the "year" value.

Please suggest me how to go over this? is there any good alternative to "last"?

TIA
Prvn
# 2  
Old 07-28-2009
You can use "fwtmp" get the raw information from "wtmp" formatted in ascii. The full date is then available for further processing. With a bit of cleverness you can fish out details for one user. Don't expand the whole file to disc - it will be very large.

Can't check on Solaris (including the name of the accounting file), but I believe that sample usage will look something like this:

Code:
cat /usr/adm/wtmp | /usr/sbin/acct/fwtmp | grep \^"$USERNAME} "

Note the space character after the username.
See "man 4 wtmp" for the file format and the meaning of the various flags so you can find the "login" records.
With a little bit of lateral thought you can select records for a user for a given year to a file and then convert the file back to wtmp format with "fwtmp" and then read that file with "last". Of course avoiding overwriting your main "wtmp" file throughout.

It is advisible to start new accounting files periodically. Even if just to stop them reaching 2 Gigabytes. We copy the file periodically to an archive filename then null the file (>filename).

Last edited by methyl; 07-28-2009 at 09:51 AM..
# 3  
Old 07-28-2009
Thanks much Methyl!!

I should be able to get though with "fwtmp" which worked great on Solaris.

Prvn
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

What is the significance of sh -s in ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh?

Please can you help me understand the significance of providing arguments under sh -s in > ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh (4 Replies)
Discussion started by: Sree10
4 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. UNIX for Advanced & Expert Users

How to allow particular user only to login as a root using "ssh" ?

Q1 I want to allow particular user only to login into root using ssh. I have set PermitRootLogin no for security purpose but I want to allow some of the users to login as a root using ssh how to do this? I have tried with Allowusers user1 user2 its working for only the user1 and... (3 Replies)
Discussion started by: ungalnanban
3 Replies

5. UNIX for Dummies Questions & Answers

how to install "source" command!/ broken "login.cl"!

Hello, I am new to this forums and this is my first "asking help" message! i have 2 problems: 1- for unknown reasons the "source" command is not avalable in my system (UBUNTU). i can't either see it in my bin directory! 2- again for unknown reasons the "login.cl" file in the home... (0 Replies)
Discussion started by: astrosona
0 Replies

6. Shell Programming and Scripting

communicating wth another user aside from "wall" and "write"

Hi, Can anyone suggest a Unix command or c-shell algorithm to simulate to behavior of "wall" command minus the "all users"? What I'm trying to do is to send a notice to just one particular user but i dont want other remotely-logged-on users to receive the message (on the pseudo-terminals). I... (6 Replies)
Discussion started by: Deanne
6 Replies

7. UNIX for Dummies Questions & Answers

How to find out the exact year in "Last modified time" using ls command

Hi, I understand that the ls command with "-l" option generates the "last modified time" of specific directory. However, some generated results displayed the "last modified time" with detail about the last modified year, for example: -rwxrwxrwx+ 1 smith dev 10876 May 16 2005 part2 ... (6 Replies)
Discussion started by: Dophlinne
6 Replies

8. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question