LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-08-2009, 01:22 AM   #1
mmahulo
Member
 
Registered: Nov 2008
Posts: 31

Rep: Reputation: 15
How many times a user logged in


Hi all! Happy new year!

I want to write a script that can count how many times a user has logged in.
The following is what I tried and seemengly I miss something somewhere:
times=$(who | grep $* | wc -l)
echo "$* has logged in $times times"


Please help.
 
Old 01-08-2009, 01:31 AM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
"who" does not give that kind of historical information. See "man who" or "info coreutils 'who invocation'".

Last edited by Didier Spaier; 01-08-2009 at 01:32 AM. Reason: Typo
 
Old 01-08-2009, 01:36 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Rep: Reputation: 135Reputation: 135
just try the command "last"
 
Old 01-08-2009, 02:25 AM   #4
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
Yesterday I checked with my box and "last" failed to report my brothers login .
This is how I verified his login.


Code:
grep LOGIN /var/log/messages |grep username | tail -1
You can count them with

Code:
grep LOGIN /var/log/messages |grep username | wc -l

Last edited by ZAMO; 01-08-2009 at 02:29 AM.
 
Old 01-08-2009, 02:56 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
The last command reads data from /var/log/wtmp by default, and most distros set things up so this file is rotated weekly or monthly (or when it gets big). If you want long term historical data, you'll have to modify your system not to do this (usually by modifying logrotate.conf), or by just backing up the wtmp file. Automatically backing up log files is not a bad idea for security auditing anyhow, as an attacker who manages to gain root access can falsify log entries.
 
Old 01-08-2009, 08:25 AM   #6
mmahulo
Member
 
Registered: Nov 2008
Posts: 31

Original Poster
Rep: Reputation: 15
I tried : grep LOGIN /var/log/messages |grep username | tail -1

but it seems like it does not apply to SuSE Linux as I am using one. Or else, it's maybe because I don't have root access. Another suggestion please...
 
Old 01-08-2009, 11:06 AM   #7
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
Did you try
Code:
 sudo grep LOGIN /var/log/messages |grep username | tail -1
?
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gnome: Auto mounting external devices as first user logged in, not current user yitzle Linux - Software 4 04-01-2008 09:43 AM
What is the command for finding the last 3 times the user had logged into the system? Linux_interest Linux - Newbie 3 08-27-2004 05:02 AM
What is the command for finding the last 3 times the user had logged into the system? Linux_interest Linux - General 1 08-27-2004 03:14 AM
iptables and limiting the number of times an event gets logged drexel Linux - Security 3 02-09-2004 08:59 AM
mozilla works fine when logged in as a user but crashes when logged in as root jimi Linux - General 6 04-02-2003 08:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration