-
-
Save positiveque/5c1795ee145f47112d125435422d2cb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Reads the date parameter. empty then date is today | |
if [ -z "$1" ] | |
then | |
date=$(date +"%Y-%m-%d") | |
else | |
date=$1 | |
fi | |
#Setting initial variables. Workdir is where logs are writen, customers file are read and so on | |
workdir="/root" | |
#A file with the following values (customer,key,secret,region,bucket,expectedsize) must exists in the | |
#Workdir | |
while IFS=, read -r customer key secret region bucket expectedsize | |
do | |
echo "Listing files into customer $customer's bucket" | |
export AWS_ACCESS_KEY_ID=$key | |
export AWS_SECRET_ACCESS_KEY=$secret | |
export AWS_DEFAULT_REGION=$region | |
aws s3 ls --recursive s3://$bucket > "$workdir/$customer.log" | |
detectedsize=$(cat $customer.log | grep $date | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print int(total/1024/1024)}') | |
if [ $expectedsize -lt $detectedsize ] | |
then | |
subject="Backup ok" | |
mensagem="Tudo certo com o backup da empresa $customer. Backup esperado eh de $expectedsize MB e encontrado eh de $detectedsize MB para a data de $date" | |
echo $mensagem | |
else | |
subject="PROBLEMA COM BACKUP" | |
mensagem="PROBLEMA COM BACKUP na empresa $customer. Backup esperado eh de $expectedsize MB e encontrado eh de $detectedsize MB para a data de $date" | |
echo $mensagem | |
fi | |
#In the following for the Telegram ID's to send the message | |
for i in 34232342 23423234; | |
do | |
$workdir/telegram.sh $i "$subject" "$mensagem" | |
done | |
done < "$workdir/customers" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Autor: remontti.com.br | |
TOKEN="YOUR-TELEGRAM-BOT-TOKEN-HERE-WITHOUT-THE-BOT-PART" | |
USER=$1 | |
SUBJECT=$2 | |
MESSAGE=$3 | |
NL=" | |
" | |
curl --silent -X POST --data-urlencode "chat_id=${USER}" --data-urlencode "text=${SUBJECT}${NL}${NL}${MESSAGE}" "https://api.telegram.org/bot${TOKEN}/sendMessage?disable_web_pa | |
ge_preview=true&parse_mode=html" | grep -q '"ok":true' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment