LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 02: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, 02:31 AM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2 on Lenovo Thinkpad W520
Posts: 7,864

Rep: Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777
"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 02:32 AM. Reason: Typo
 
Old 01-08-2009, 02:36 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,363

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

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 03:29 AM.
 
Old 01-08-2009, 03:56 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
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, 09: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, 12:06 PM   #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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10: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 06: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 04:14 AM
iptables and limiting the number of times an event gets logged drexel Linux - Security 3 02-09-2004 09: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 09:34 PM

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

All times are GMT -5. The time now is 11:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration