473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

"last" command returning duplicates

Hi

I am running a “last” command and saving the output to a file, which I am going to
ftp to my PC for loading into a DB table.

last > last.txt

I am finding that I am getting lots of duplicate entries for most logins in last.txt.

Eg

userabc pts/3 12.42.35.120 Mon Jun 14 09:17 - 09:19 (03:00)
userabc pts/3 12.42.35.120 Mon Jun 14 09:14 - 09:16 (02:00)
userabc pts/3 12.42.35.120 Mon Jun 14 09:12 - 09:13 (01:00)
userdef pts/2 12.42.35.126 Mon Jun 14 10:27 - 09:28 (01:00)
userdef pts/2 12.42.35.126 Mon Jun 14 10:24 - 09:26 (02:00)


Is there a way to only retrieve the last login for each user ?

Thanks
Dec 16 '10 #1
2 2672
ashitpro
542 Expert 512MB
Instead of 'last' try 'lastlog'.

It should display the username and last login time.
Something like this:

Expand|Select|Wrap|Line Numbers
  1. Username         Port     From             Latest
  2. root             pts/5    172.18.28.86     Fri Dec 17 14:53:18 +0530 2010
  3. bin                                        **Never logged in**
  4. daemon                                     **Never logged in**
  5. adm                                        **Never logged in**
  6. lp                                         **Never logged in**
  7. sync                                       **Never logged in**
  8. shutdown                                   **Never logged in**
  9. halt                                       **Never logged in**
  10.  
  11.  
If you are not happy with "Never logged in" message, you can use following command:

lastlog | grep -v 'Never'

--Ash
Dec 17 '10 #2
Hi Ashitpro
My version of unix does not recognise your "lastlog" command.
Thanks anyway.

PS The command :
awk '$1==u || /^$/ {next} {print; u=$1}'
removes duplicates for me !
Dec 17 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.