#!/bin/bash ### ## ## Looks for a string that shows a post was found for a search listing. ## When found, alert emails are sent. ## ### # Define parameters URL="https://www.dfl.de/de/?s=Sicherheitskontext&submit=" SEARCH_STRING='Teilnehmende schließen Zertifikatsstudium'; RECIPIENTS=("r.hellyer@syde.com" "ryanhellyer@gmail.com") SUBJECT="DFL search down" BODY="Alert: The DFL search system is currently down." # Set absolute path to msmtp config export MSMTPRC="/etc/msmtprc" # Create log directory if it doesn't exist LOG_DIR="/var/log/msmtp" [ ! -d "$LOG_DIR" ] && sudo mkdir -p "$LOG_DIR" && sudo chmod 777 "$LOG_DIR" # Fetch the webpage and check for the string if ! webpage_content=$(curl -s "$URL"); then echo "Failed to fetch webpage" >> "$LOG_DIR/dfl-check.log" exit 1 fi echo $webpage_content > "$LOG_DIR/dfl.html" # Check if the string exists in the webpage content if echo "$webpage_content" | grep -q "$SEARCH_STRING"; then echo "$(date): Search string found - system working normally" >> "$LOG_DIR/dfl-check.log" exit 0 else echo "$(date): Search string NOT found - sending alert" >> "$LOG_DIR/dfl-check.log" # String not found - send alert email if command -v msmtp >/dev/null 2>&1; then for recipient in "${RECIPIENTS[@]}"; do { echo "To: $recipient" echo "Subject: $SUBJECT" echo "Content-Type: text/plain" echo echo "$BODY" echo "Time: $(date)" } | msmtp --file=/etc/msmtprc "$recipient" 2>> "$LOG_DIR/dfl-check.log" if [ $? -eq 0 ]; then echo "$(date): Alert email sent successfully to $recipient" >> "$LOG_DIR/dfl-check.log" else echo "$(date): Failed to send alert email to $recipient" >> "$LOG_DIR/dfl-check.log" exit 1 fi done exit 0 else echo "$(date): Error: msmtp not found" >> "$LOG_DIR/dfl-check.log" exit 1 fi fi