Home  >  Q&A  >  body text

linux编程 - Linux如何查看每日失败的登录记录?

PHP中文网PHP中文网2764 days ago463

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 14:53:53

    Can you post a log of failed login? This can be achieved using cat, grep, and awk commands. I don’t know the specific format and cannot correctly write the matching shell


    2016-5-14 10:01:36 Add a script.

    Create a log_login_by_ip.sh file with the following content:

    #!/bin/bash
    clear
    if [[ $# -eq 0 ]]
    then
        week=(`env LANG=en_US.UTF-8 date '+%a'`)
        month=(`env LANG=en_US.UTF-8 date '+%b'`)
        day=(`env LANG=en_US.UTF-8 date '+%d' | grep -ioP "[1-9]+"`)
    
        # test data
        #week=Fri
        #month=May
        #day=13
       lastb -a|grep -iE $week"[ ]+"$month"[ ]+"$day|awk  -F"[ ]+" '{print $NF}'|sort|uniq
    fi

    Output result:

    Note:
    If you no longer want to clear the screen after executing this script, please block or delete the clear command.
    Execute command:

    sh ./log_login_by_ip.sh

    reply
    0
  • Cancelreply