If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Last Login date for users

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-08, 14:24
jarheadc jarheadc is offline
Registered User
 
Join Date: Jan 2008
Posts: 2
Last Login date for users

I've written a simple ksh script to list the last login for all the users on my systems. The problem is that it uses the last command and if the user hasn't logged in since the wtmp file was created I only get the following from last:
.
wtmp begins Feb 23 11:40
.
My script looks like this

#!/bin/ksh

for i in `lsuser -a ALL`
do
echo `last -1 $i` >> /tmp/lastloginnew.txt
done


I also found the following script here, on this forum, but it was from 2005 so I decided that it wasn't probably being monitored.

#!/bin/ksh

UIDS=`last | cut -f1 -d' ' | cat -n | sort -k 2.1 | uniq -f1 | sort
-n | cut -f2`

for UID in $UIDS
do
last -1 $UID
done

Both of these give me the same thing, just that the first redirects the output to a file that I can e-mail to other team members.

What I'm looking for is some way for the script to print the user name prior to running the last command so that each line will give me the user name the last command is running for. Any help would be greatly appreciated.

-Chas
Reply With Quote
  #2 (permalink)  
Old 01-21-08, 06:19
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
like this?
echo "$uid: `last -1 $uid | sed '/^$/d'`"
Reply With Quote
  #3 (permalink)  
Old 01-21-08, 08:13
jarheadc jarheadc is offline
Registered User
 
Join Date: Jan 2008
Posts: 2
Thanks so much. I'll let you know how it goes.

-Chas
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On