Script to display last login date/time?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to display last login date/time?
# 1  
Old 12-03-2001
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
# 2  
Old 12-03-2001
last -1 <username> will show the last time the user logged in. Is this what you were looking for or is that still too much information?
# 3  
Old 12-03-2001
I wanted to produce a text file that had each users last login info in it. My script is as follows, but it produces some weird errors. Any obvious mistakes?

#!/sbin/sh
for i in `niscat passwd.org_dir | cut -f1 -d":"`
do
#echo
echo `last $i | head -1 | awk '{print $1" "$4" "$5" "$6}'` >> recentlogin.txt
#echo
done
# 4  
Old 12-06-2001
lastlogin for users

Here is a script that works for me.


find /home -name .lastlogin -mtime +60 > /tmp/lastlogin.rpt {} \;
cat /tmp/lastlogin.rpt awk -F: '{ print $1, $4 }' >> /tmp/lastlogin.info

or something like that.

You can make this better by creating a "for loop" to copy each user info right after the info on the .lastlogin file that would probably work better than this little bit.

Enjoy!

You can modify this to capture data from the passwd file and associate it with the file owner which is the user.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display Date and Time in GDB

In gdb is there any way we can display date/time in first column while debugging or is there any command which will print date/time? I am asking this just to know when exactly a breakpoint got hit. (6 Replies)
Discussion started by: rupeshkp728
6 Replies

2. Shell Programming and Scripting

Display files created on particular date & time

Hi , I have BASH system & i am trying to display the files created on a particular date and time, and after displaying those files I also want to delete all those files.Can anyone of you help me out for this............. Thanx Original post contents restored... Please do not erase the question... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

3. UNIX for Dummies Questions & Answers

How to always display date/time regardless of directory?

I found via Google a way to show the date and time stamp once I log in. However, whenever I cd to another directory it doesn't display the correct path. Here are the relevant parts from my .kshrc : unset _h _m _s eval $(date "+_h=%H ;_m=%M ;_s=%S") ((SECONDS =... (3 Replies)
Discussion started by: Mike F.
3 Replies

4. 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

5. Shell Programming and Scripting

script to display time

hey folks, i am stuc in this problem. You all might help me out. I want to write a BASH script to display time every 15 seconds using %r field descriptor. And want to clear the window each time before displaying time using clear command. Please help me out (3 Replies)
Discussion started by: manojrsb
3 Replies

6. 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

7. 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

8. Shell Programming and Scripting

date and time to display on the terminal

hi all, am trying to 'grep' some text from a log file and use the 'cut' command to read from that line i just grep'ed to extract date/time and response times. code sniplet i am using is : grep -i 'text to grep' Out.log | while read LINE; do ... (11 Replies)
Discussion started by: cesarNZ
11 Replies

9. AIX

Unable to display the date-time in seconds on AIX

Hi, In unix the command "date +%s" displays the date-time in seconds since â00:00:00 1970-01-01 UTCâ (a GNU extension) when executed on unix: -sh-2.05b$ date +%s 1152092690 I tried with all the format control output but unable to display the date-time in seconds i,e as in unix format. Can... (6 Replies)
Discussion started by: me_haroon
6 Replies

10. Solaris

display date n Time

Hi Friends, Can any one guide me regarding 'Display the date and time' command other than the command 'date' thanks n regards SsRrIi (1 Reply)
Discussion started by: SsRrIi
1 Replies
Login or Register to Ask a Question