Boas pessoal,
Surgiu algo inusitado pra mim, eu não desabilitei um script de envio de email no meu crontab, e coloquei o novo que realiza o envio de backup do BD para o S3 da AWS.
Mas neste script de envio não há nada relacionado a envio de email e mesmo assim eu recebi...
Segue código:
monitora o apache para resposta de off:
#!/bin/bash
resposta_http=$(curl --write-out '%{http_code}\n' --silent --output /dev/null http://localhost)
if [ "$resposta_http" -ne 200 ]; then
mail -s "Problema no servidor" email@email.com<<del
Houve um problema no servidor e os usuários pararam de ter acesso ao conteúdo web.
del
systemctl restart apache2.service
fi
realiza backup do BD e envia para AWS:
#!/bin/bash
CAMINHO_BACKUP=/home/yan/alura/shell-script/backup-amazon
cd $CAMINHO_BACKUP || exit
data=$(date +%F-%H-%M-%S)
if [ ! -d $data ]
then
mkdir $data
fi
tabelas=$(mysql -u root alura_shell -e "show tables;" | grep -v Tables)
for tabela in $tabelas
do
mysqldump -u root alura_shell $tabela > $CAMINHO_BACKUP/$data/$tabela.sql
done
aws s3 sync $CAMINHO_BACKUP s3://alura-shell-yan
crontab:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
*2/ * * * * /home/yan/alura/shell-script/scripts/monitorar-server.sh
10 12 * * * /home/yan/alura/shell-script/scripts/backup-amazon-bd.sh
cron status:
cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-08-23 11:36:33 -03; 34min ago
Docs: man:cron(8)
Main PID: 135 (cron)
Tasks: 1 (limit: 19157)
Memory: 3.6M
CGroup: /system.slice/cron.service
└─135 /usr/sbin/cron -f -P
Aug 23 12:09:01 YAMA-I CRON[9328]: pam_unix(cron:session): session closed for user root
Aug 23 12:10:01 YAMA-I CRON[9506]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Aug 23 12:10:01 YAMA-I CRON[9507]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Aug 23 12:10:01 YAMA-I CRON[9508]: (root) CMD (/home/yan/alura/shell-script/scripts/backup-amazon-bd.sh)
Aug 23 12:10:01 YAMA-I CRON[9509]: (root) CMD (/home/yan/alura/shell-script/scripts/monitorar-server.sh )
Aug 23 12:10:01 YAMA-I CRON[9507]: pam_unix(cron:session): session closed for user root
Aug 23 12:10:02 YAMA-I sSMTP[9532]: Creating SSL connection to host
Aug 23 12:10:03 YAMA-I sSMTP[9532]: SSL connection using ECDHE_RSA_AES_256_GCM_SHA384
Aug 23 12:10:07 YAMA-I sSMTP[9532]: Sent mail for root@Yan (221 2.0.0 closing connection l10-20020a056830154a00b006b87f593877sm5691840otp.37 - gsmtp) uid=0 username=root outbytes=973
Aug 23 12:10:07 YAMA-I CRON[9506]: pam_unix(cron:session): session closed for user root
email recebido:
Será que foi por conta de eu não "fechar" o comando mail?