Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Script to check the login attempts of a particular user into the server.  (Read 1655 times)

0 Members and 1 Guest are viewing this topic.

jerrys

  • Guest
Hi all,

Here is a bash script to check the number of login attempts of a user into the server, this script displays all the users in the system and provides you the option to check the login attempt details of a particular user.

------------------------------------------------------------------------------------------
#!/bin/bash
echo ======================================================================
echo The users in the System are:
awk -F'[/:]' '{if ($3==0) print $1}' /etc/passwd
awk -F'[/:]' '{if ($3 >=500 && $3 != 65534) print $1}' /etc/passwd
echo ""
echo Enter the name of the user whose logins needs to be counted:
read username
echo ""
echo The number of times the user $username has successfully logged into the custom container is
less /var/log/secure |grep $username | grep -ic accepted
echo ""

echo The number of failed login attempts of the user $username into the custom container is
less /var/log/secure |grep $username | grep "authentication failure" | wc -l
echo ""

echo ======================================================================

------------------------------------------------------------------------------------------
Please feel free to modify :)