UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 20th, 2004, 11:00 PM
Vinod V Vinod V is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 36 Vinod V User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 5
Unhappy Getting Users' last login timestamp

Does anyone know how to get the last login timestamp for all the users who have used the system. I use logins -utx but it dosent give the last logins of the users. Can anyone help? Thx in adv.

Reply With Quote
  #2  
Old April 21st, 2004, 12:19 AM
Vinod V Vinod V is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 36 Vinod V User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 5
Basically i have a list of users already sorted in a file and i use the logins commands to get all the users that have logged in to the system and uniq the two lists to get the list of users who are not in the result of the logins command. Then i have to get the last login for this list of users and check whether it more than 90 days old...if yes...then i create another list with those users.

get users's login with last login --> grep users from another file --> compare both and create a new list with users not in the results of the first step --> get the last logins of the users in the new list --> if more than 90 days old then put that user in a new list.

Any kind of help is greatly appreciated Thnx in adv.

Reply With Quote
  #3  
Old April 21st, 2004, 05:33 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,297 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 9 m 17 sec
Reputation Power: 104
Send a message via ICQ to christo Send a message via Yahoo to christo
finger


christo

Reply With Quote
  #4  
Old April 21st, 2004, 08:14 AM
khemani khemani is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 4 khemani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Vinod V
Does anyone know how to get the last login timestamp for all the users who have used the system. I use logins -utx but it dosent give the last logins of the users. Can anyone help? Thx in adv.


try running:

last

to get a list of all logins in /var/adm/wtmpx (or wherever your installation of unix logs logins).

to get a history of logins for a given user, run:

last <user>

if your host rotates the wtmpx file, you can query a given wtmpx file for a history of logins by running:

last -f <path to wtmpx file>

Reply With Quote
  #5  
Old April 21st, 2004, 08:33 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,297 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 9 m 17 sec
Reputation Power: 104
Send a message via ICQ to christo Send a message via Yahoo to christo
why not just use finger to get the last login for the user...

eg$ finger chris
Login: chris Name: chris lacy-hulbert
Directory: /home/chris Shell: /bin/bash
Office: 07751 615 397
On since Wed Apr 21 10:05 (BST) on pts/0 from wormwood.mailbox.net.uk
No mail.
No Plan.

the matching is then a no-brainer in PERL.

christo

Reply With Quote
  #6  
Old April 21st, 2004, 09:43 PM
Vinod V Vinod V is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 36 Vinod V User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 5
I could do that but i have to compare two diff sets of user lists against each other...eg....File1(static list) and File2(Extracted list)....I have to compare file2 with file1 and extract a new list of users who dont exist in file to file3....then get their last logins and then remove those whose last login is more than 90 days old......does that seem logical? thnx

Reply With Quote
  #7  
Old April 22nd, 2004, 10:41 AM
jetiii jetiii is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 6 jetiii User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Also if the user is not logged on, it does not give the last log in time.

Reply With Quote
  #8  
Old April 22nd, 2004, 11:09 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,297 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 9 m 17 sec
Reputation Power: 104
Send a message via ICQ to christo Send a message via Yahoo to christo
Quote:
Originally Posted by jetiii
Also if the user is not logged on, it does not give the last log in time.


yes it does:

If never logged in:

bash-2.05b# finger spiration
Login: spiration Name: spiration
Directory: /home/spiration Shell: /bin/bash
Never logged in.
No mail.
No Plan.

If not currently logged in:

bash-2.05b# finger spira
Login: spira Name: spira
Directory: /home/spira Shell: /bin/bash
Last login Mon May 5 10:21 2003 (BST) on pts/2 from 10.0.0.15
No mail.
No Plan.

what more could you need?

christo

Reply With Quote
  #9  
Old August 26th, 2004, 10:36 AM
Straylight Straylight is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 Straylight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am trying to figure this out as well.....although i dont need it to be as complicated. What i have right now is a file with all the usernames (from /etc/passwd) Now is there a way that i can make the finger commad run through that file and finger each username and send the results to a new file?

thanks,

straylight

Reply With Quote
  #10  
Old August 26th, 2004, 11:12 AM
faulkner faulkner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 103 faulkner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Quote:
Originally Posted by Straylight
Now is there a way that i can make the finger commad run through that file and finger each username and send the results to a new file?

You can write a scipt that will finger each user and send result to file.
*note: If you go around fingering users, you might get a call from HR.

Reply With Quote
  #11  
Old August 26th, 2004, 11:17 AM
Straylight Straylight is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 Straylight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ha, yeah i am sure HR would get a real kick out of that! Anyway, i know you can write a script....i need some more detail than that though

Reply With Quote
  #12  
Old August 26th, 2004, 12:16 PM
jlk's Avatar
jlk jlk is offline
Perl Jedi
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: New Hampshire
Posts: 108 jlk User rank is Sergeant (500 - 2000 Reputation Level)jlk User rank is Sergeant (500 - 2000 Reputation Level)jlk User rank is Sergeant (500 - 2000 Reputation Level)jlk User rank is Sergeant (500 - 2000 Reputation Level)jlk User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 41 m 53 sec
Reputation Power: 15
Quote:
Originally Posted by Vinod V
I could do that but i have to compare two diff sets of user lists against each other...eg....File1(static list) and File2(Extracted list)....I have to compare file2 with file1 and extract a new list of users who dont exist in file to file3....then get their last logins and then remove those whose last login is more than 90 days old......does that seem logical? thnx


This sounds suspiciously like a homework question. You decide, my mind is already made up.

Regards,

jlk

Reply With Quote
  #13  
Old August 26th, 2004, 12:39 PM
Straylight Straylight is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 Straylight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My question is not a homework question.....i would just like to know how i can make the finger command finger every username in /etc/passwd. I am sure its not very hard, so if you have USEFUL information please bring it on

thanks,

straylight

Reply With Quote
  #14  
Old August 26th, 2004, 01:25 PM
faulkner faulkner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 103 faulkner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Code:
#!/usr/bin/perl

# assuming all names are on a seperate line
open (FILE, "/file_with_names") || die "$!";
while (<FILE>)
{
   chomp;
   push @users, $_;
}
close FILE;

foreach $name (@users) 
{
   `finger $name >> OutputFile`;
    print "------------------" >> OutputFile;  #seperator
}

This is untested perl, but should work.

Reply With Quote
  #15  
Old August 27th, 2004, 06:42 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,089 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 3 h 40 m 34 sec
Reputation Power: 9
fantastic, i wonder how many people insist to use the
wrong tool 4 the wrong job. really fantastic.
btw faulkner try:
Code:
     s/\<\(sep\).\(rate\)\>/\1a\2/g


Straylight: the job is a 3-lines shell-script like:

Code:
#!/bin/sh
(
   for name in `sed 's/:.*//' /etc/passwd`
   do finger $name
   done
) >output

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Getting Users' last login timestamp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread