From 9a3be2200b29d09a87fd3f931d075922464ccb85 Mon Sep 17 00:00:00 2001 From: Alban Bronisz Date: Fri, 8 Jan 2021 19:13:29 +0000 Subject: [PATCH] First version --- README.md | 29 +++++++++++++++++++++++++++++ example.msmtprc | 14 ++++++++++++++ msg.txt | 5 +++++ warn-if-broken-url.sh | 18 ++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 README.md create mode 100644 example.msmtprc create mode 100644 msg.txt create mode 100755 warn-if-broken-url.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..4210681 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ + + +Install +======= + +Install `msmtp` package: + + sudo apt install msmtp + +Configuration, see [ubuntu-rf.org](https://doc.ubuntu-fr.org/tutoriel/comment_envoyer_un_mail_par_smtp_en_ligne_de_commande) + + +Use +=== + +To add it to the cron tab: + + crontab -e + +The add new line (to run the check once per hour) + + 1 * * * * /home/alban/outils/warn-if-broken/warn-if-broken-url.sh >/dev/null 2>&1 + + +**Note:** + - Normaly cron send task outputs (echo) via mail. As the MTA (Mail Transfert Agent), may not be set up, +the crontab line redirect the outputs into `/dev/null`. + - No sudo is needed, msmtp and crontab are call with current user. + - The logs can be seen using (with sudo): `sudo grep CRON /var/log/syslog` diff --git a/example.msmtprc b/example.msmtprc new file mode 100644 index 0000000..563e5d5 --- /dev/null +++ b/example.msmtprc @@ -0,0 +1,14 @@ +account default +tls on +host mail.gandi.net +port 587 + +tls_starttls on +tls_certcheck on +tls_trust_file /etc/ssl/certs/ca-certificates.crt + +from Service Caracals + +auth on +user service@caracals.org +password XXXXXX diff --git a/msg.txt b/msg.txt new file mode 100644 index 0000000..ec39365 --- /dev/null +++ b/msg.txt @@ -0,0 +1,5 @@ +From: Service Caracals +To: alban.bronisz@gmail.com +Subject: Cachet est mort !!!! + +Voir https://status.caracals.org diff --git a/warn-if-broken-url.sh b/warn-if-broken-url.sh new file mode 100755 index 0000000..2e15bb5 --- /dev/null +++ b/warn-if-broken-url.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -eu + + +URL="https://status.caracals.org" + +SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" + +pushd ${SCRIPT_PATH} > /dev/null + +if ret=$(curl -s -f "${URL}"); then + echo "Marche" +else + echo "Marche pôs" + cat msg.txt | msmtp alban.bronisz@gmail.com +fi + +popd