Using the Linux utility, nc, you can write a small script to test for the existance of a given mail server and then take action if it appears not to exist.
#!/bin/bash
TEST_SERVER=127.0.0.1
TEST_PORT=25
OUTPUTLOG=/tmp/testoutput.txt
rm -f $OUTPUTLOG
# Gather the connection details
/usr/bin/nc -zv -w 15 $TEST_SERVER $TEST_PORT 1&> $OUTPUTLOG
if grep "succeeded" $OUTPUTLOG; then
echo 'Server is up'
else
echo 'Server is down'
echo 'do something here'
fi
The
nc utility is a very powerful little utility that can be used for a variety of uses, including acting as a server for incoming connections.
tags: linux command line
links: digg this del.icio.us technorati