Getting the number of UNIX login attempts

Is there a way to find out how many times a user has logged on to the system (UNIX) using who

or some other method?

+3


source to share


4 answers


If you want count

how many times a user is logged in then it cannot be done with command-line

IMO .... especially because there is an option sudo

to pretend to be another user, which can break your logic - if you have

Also, how many times

must have a timeline ( from when

before when

) .. so you need to have an upper timeline from which you want to track the account. It would all be a mess perfect to maintaincount



If I need to keep track of it, I would rather have script

and maintain db-table

keeping track of count

users

that register!

+2


source


you can refer to: Latest unix command



and then you can manipulate the result for counting or whatever you do.

+2


source


You can use last

:

last | grep ^username| grep 'logged in' | wc -l

      

For example:

$ last | grep ^igor | grep 'still logged'
igor     pts/9        astaro       Thu Aug 28 09:55   still logged in   

      

It takes information about user logins from wtmp

-database ( /var/log/wtmp

). This means that only those records that are in this database are displayed. You should keep in mind that tt it is possible that if a user has been logged in for a long time, there is no information about that login in it (due to the turn).

Also, I should note that the concept of "how many times a user has logged in" is a bit vague. The user can have processes running but not logged in (or at least not logged into wtmp

), the user can use su

, etc.

Using this method, you can count the number of open user terminal sessions:

$ ps aux | grep ^igor | fgrep S+ | wc -l
12

      

+1


source


You can add logic to / etc / profile. When you add a line to the log file, don't forget about the household. You might want to create a log file daily and delete files older than 10 days.

0


source







All Articles