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. |
"who" does not give that kind of historical information. See "man who" or "info coreutils 'who invocation'".
|
just try the command "last"
|
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 Code:
grep LOGIN /var/log/messages |grep username | wc -l |
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.
|
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... |
Did you try
Code:
sudo grep LOGIN /var/log/messages |grep username | tail -1 |
All times are GMT -5. The time now is 04:21 AM. |