Lewati ke isi

script ssh login alert

contoh script ssh login alert

#!/bin/bash

#init
initCount=0
logs=/var/log/commandss.log

#File
msg_caption=/tmp/telegram_msg_caption.txt

#Chat ID dan bot token Telegram
chat_id="-"
token=""

#kirim
function sendAlert
{
        curl -s -F chat_id=$chat_id -F text="$caption" https://api.telegram.org/bot$token/sendMessage #> /dev/null 2&>1
}

#Monitoring Server
while true
do
    lastCount=$(wc -c $logs | awk '{print $1}')

    if (( $lastCount > $initCount )); then
        msg=$(tail -n 2 $logs | grep passwd) #GetLastLineLog

        if [[ -n $msg ]]; then
            echo -e "alert!!!\n\nServer Time : $(date +"%d %b %Y %T")\n\n$msg" > $msg_caption #set Caption / Pesan
            caption=$(<$msg_caption)
            sendAlert
            echo "Alert Terkirim"
        fi

        initCount=$lastCount
        rm -f $msg_caption
    fi

    sleep 2
done