Webmail Check

16 Apr

Script to check webmail tunnel is always up:

Put an entry into /etc/inittab like:
st:2345:respawn:/usr/bin/ssh -n -C -x -R 2501:localhost:443 squid@externalserver.com -o ‘GatewayPorts yes’ sleep 5000

Then have the script attached running in crontab every minute to monitor it the tunnel.

# iisjsoo 16 Feb 2004
# This is a quick hacked together script to monitor external
# webmail. If it finds it cannot reach external webmail it
# kills the ssh tunnel program – /etc/inittab should automagically
# restart it.
# Note that the file ‘connection_test.php’ must exist on the site to be
# checked. This script should return ‘connection OK’
# This script should probably be put in a cron job and run every minute.

if [ -e “/tmp/webmail_check.tmp” ]
rm /tmp/webmail_check.tmp

curl –max-time 5 -o /tmp/webmail_check.tmp https://mail.imvs.org/connection_test.php 2>/dev/null
#curl -o /tmp/webmail_check.tmp http://www.google.com 2>/dev/null

if [ ! -e “/tmp/webmail_check.tmp” ]
echo “/tmp/webmail_check.tmp does NOT exist, i believe the Internet is down or maybe the websites down!”
echo ” Bailing out….”

ANSWER=`cat /tmp/webmail_check.tmp`

if [ “$ANSWER” = “connection OK” ]
echo `date` ” Connection OK”
echo `date` ” Connection FAILED”
CURRENT_PID=`ps -ef | grep “ssh -n -C -x -R” | grep -v grep | awk ‘{print $2}’`
if [ -n CURRENT_PID ]
echo ” An ssh process is currently running:” $CURRENT_PID
echo ” Killing the process – this should cause an auto re-start”
kill -9 $CURRENT_PID
echo ” There is no ssh process currently running. /etc/inittab should have started it. HELP!”


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: