Monitoring a Linux process by PID and sending a e-mail notification upon failure

Posted by & filed under BASH, Email, Linux, Programming.

One of my clients needs their vendor to be alerted when their Backup Exec service crashes. I wrote the following quick-n-dirty batch script intended to be ran as a cron job.

#!/bin/bash
# Process Monitor
# Send e-mail alerts when service goes down
# -------------------------------------------------------------------------
# Author: Nathan Riley
# -------------------------------------------------------------------------
SUBJECT="Backup Exec Agent Failure"
EMAIL="address@email.to"
EMAILMESSAGE="/tmp/emailalert.txt"

#path to pgrep command
PGREP="/usr/bin/pgrep"

# Daemon name,
DAEMON="httpd"

# find daemon pid
$PGREP ${DAEMON}

if [ $? -ne 0 ] # if daemon not running
then
# Generate email message body
echo "This is servername at location. The Backup Exec service is no longer running." > $EMAILMESSAGE
# send email alert
/usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi

And the cron line would be something like this:

*/5 * * * * root /root/restart.sh  >/dev/null 2>&1

Removing MX records from a Microsoft DNS Server via script

Posted by & filed under DNS, Email, Programming, Server Admin.

We recently switched our barracuda system from using two equally weighted MX records to using one MX record that points to two same-named A records. We are hoping that this will help better load balance the Barracuda cluster. I wrote a quick-n-dirty batch script to remove the second barracuda MX record from our DNS zones:

for /f %%h in (domains.txt) do dnscmd /RecordDelete %%h @ MX 10 servername.net /f

This script takes the input file domains.txt and processes each domain contained in the text file. The format is one domain per line…