how can i view the amount of times each user has connected to my system
Hi
I am connected to a network via SHH. Now, i know how i can see which users are logged on as well, but how can i see how many times each user has connected? this refering to users that have logged on at least once... thank you |
cat /var/log/auth.log | grep "Accepted" | grep "<username>" | wc
Keep in mind that will only count the amount since the log has been rolled over.. I don't know of a way to know how many since the server was deployed. |
Well, take a look at last, lastb and lastlog. You may have to script a solution instead, which would require working with /var/log/wtmp and /var/log/btmp
I don't know of any specific way, you see |
thank you very much for the immediate answers...
@jamescondron: i also thought scripting the solution is the best way to go... as for working with /var/log/wtmp and /var/log/btmp could you explain to me what these do? anyway thank you both i am a COMPLETE newbie to Linux so my questions may sound quite stupid |
Well, certain important files have man pages too, and wtmp is the same. It is basically a binary file containing the information last uses. btmp; lastb.
Using wtmp and btmp will require something a bit more than scripting know-how, so you may find it easier to parse the output from last, lastb and lastlog. But yes, take a look at the man pages Code:
man <command> |
thanks again. i am already looking at man pages for all the commands you
refered to and it is helpful, however my problem remains on how i will count the times each user has logged on to get an result like: [<myusername>@di o g eni s ~ ] $ countlogins . sh 48 theodor pc4236 . c e id . upatras . gr 48 theodo pc4236 . c e id . upatras . gr 42 voulgari82. 1 6 9 . 1 0 . 2 9 . . . where countlogins.sh is my bash script and i.e. theodor is a user that has connected 48 times on diogenis...... so if there are any ideas about that, bring them on :D otherwise, i thank u very much for your help already and hopefully i'll find it |
Well, assume your output looks as thus:
Code:
jc@jcmain:~$ last -f /var/log/wtmp.1 -200 All we do then is count each instance of a particular username. You can get the individual ones any number of ways, you could make an array of usernames from /etc/passwd, you could just go line by line, if in array then array[user] ++, else array.append(user) etc. It kinda depends on what you want to write your script in, really |
considering what you said :) and also with some awk research i ended up with:$ awk '{count[$1]++}END{for(j in count) print j,"("count[j]" logons)"}' FS=: users.txt
where users.txt is a list of users that logged on lately... i have only one FINAL question: i want to print my final list in descending order. in the above command, where would the sort desc be put to have that result? |
All times are GMT -5. The time now is 12:18 AM. |