#!/bin/bash #init initCount=0 logs=/home/kz/log-tele.txt #File msg_caption=/tmp/telegram_msg_caption.txt #Chat ID dan bot token Telegram chat_id="1395072041" token="7215263729:AAE1F9r74VtmXF4cbM003v9Elq9GhG2Pyno" #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}') #getSizeFileLogs #DEBUG ONLY #echo before_last $lastCount #ex 100 #after reset 0 #echo before_init $initCount #ex 0 #echo "--------------------" if(($(($lastCount)) > $initCount)); then #DEBUG #echo "Kirim Alert..." msg=$(tail -n 2 $logs) #GetLastLineLog echo -e "Hallo Bro\nTerjadi ada nya Penyerangan pada Server loh!!!\n\nServer Time : $(date +"%d %b %Y %T")\n\n"$msg > $msg_caption #set Caption / Pesan caption=$(<$msg_caption) #set Caption sendAlert #Panggil Fungsi di function echo "Alert Terkirim" initCount=$lastCount rm -f $msg_caption sleep 1 fi sleep 2 #delay if Not Indication done