#!/bin/bash
# Script: check_start_mwa.sh
# Purpose: Auto-monitor/recover MWA telnet servers (Linux + Solaris SPARC compatible)
# Email body now humanized and reassuring
cd $HOME
. ./EBSapps.env run
cd $ADMIN_SCRIPTS_HOME
# Email configuration - CUSTOMIZE THESE
RECIPIENT="warehouse_team@company.com,dba_team@company.com,abdul.muqeet@company.com"
SENDER="ebs_prod@company.com"
HOSTNAME=$(hostname)
DATE=$(date +"%Y-%m-%d %H:%M:%S")
# Extract and parse ports
PORTS_LINE=$(grep -i mwaTelnetPortNo $CONTEXT_FILE | head -1)
if [ -z "$PORTS_LINE" ]; then
echo "ERROR: Unable to find mwaTelnetPortNo in context file" >&2
exit 1
fi
PORTS=$(echo "$PORTS_LINE" | sed -e 's/.*="\([^"]*\)".*/\1/' -e 's/,/ /g')
# Check and recover ports (cross-platform netstat check)
DOWN=true
STARTED_PORTS=""
for PORT in $PORTS; do
netstat -an | grep "\.$PORT " | grep LISTEN > /dev/null || \
netstat -an | grep ":$PORT " | grep LISTEN > /dev/null
if [ $? -eq 0 ]; then
DOWN=false
else
./mwactl.sh start $PORT
sleep 5
netstat -an | grep "\.$PORT " | grep LISTEN > /dev/null || \
netstat -an | grep ":$PORT " | grep LISTEN > /dev/null
if [ $? -eq 0 ]; then
STARTED_PORTS="$STARTED_PORTS $PORT"
fi
fi
done
# Dispatcher handling
DISPATCHER_PORT=$(grep -i mwa.DispatcherPort $CONTEXT_FILE | sed -e 's/.*="\([^"]*\)".*/\1/')
if [ -n "$DISPATCHER_PORT" ]; then
netstat -an | grep "\.$DISPATCHER_PORT " | grep LISTEN > /dev/null || \
netstat -an | grep ":$DISPATCHER_PORT " | grep LISTEN > /dev/null
if [ $? -ne 0 ]; then
./mwactl.sh start_dispatcher
STARTED_PORTS="$STARTED_PORTS (Dispatcher $DISPATCHER_PORT)"
fi
fi
# Exit quietly if no action needed
if [ "$DOWN" = "false" ]; then
echo "$DATE: All MWA ports already running on $HOSTNAME"
exit 0
fi
# Format started ports for email
if [ -n "$STARTED_PORTS" ]; then
STARTED_LIST=$(echo "$STARTED_PORTS" | sed 's/^ *//' | sed 's/ /<br>• /g')
STARTED_LIST="• $STARTED_LIST"
else
STARTED_LIST="Warning: No ports came up automatically — manual intervention required."
fi
# Humanized, reassuring HTML email
cat << EOF | mailx -s "MWA Services Back Online on $HOSTNAME" \
-r "$SENDER" \
-a "Content-Type: text/html" \
$RECIPIENT
<html>
<body style="font-family: Arial, sans-serif; line-height: 1.6;">
<h2 style="color: #28a745;">Good news — MWA services are back up!</h2>
<p>Hi team,</p>
<p>Our monitoring script just noticed that the MWA telnet ports were not running on <strong>$HOSTNAME</strong> at <strong>$DATE</strong>.</p>
<p>No worries — it automatically started them and confirmed they're now listening properly.</p>
<h3>Ports successfully started and validated:</h3>
<ul>
$STARTED_LIST
</ul>
<p>Mobile warehouse users should now be able to connect normally.</p>
<p>If anyone experiences any issues or needs confirmation from the floor, please reach out to <span style="color: #d9534f; font-weight: bold; font-size: 1.2em;">Abdul Muqeet</span> — he'll be happy to assist or verify functionality.</p>
<p>Thanks for your patience — we're keeping an eye on it!</p>
<p>Best regards,<br>
EBS DBA Automation<br>
(Proactive monitoring script)</p>
<hr style="margin-top: 30px;">
<small>For reference: Logs available at <code>$INST_TOP/logs/appl/admin</code></small>
</body>
</html>
EOF
echo "$DATE: Humanized MWA recovery email sent"
No comments:
Post a Comment