I thought I'd share a script I was working on for linux gw agents. Basically this is a keep alive script and I'd like to hear people's thoughts on ways to improve it, etc. I'm a bit new to bash scripting, so if there are better ways to do things I'd love to hear it. I've setup gw802hp2 on sles11 and setup a cron job as root to run this script every 5 minutes. This is a shortened version, but for every po or gateway I just add on to this template.

echo " " > /tmp/gwstat.txt

mtavar=`/usr/sbin/rcgrpwise status MTA8 | grep running | wc -l`
if [ $mtavar = 0 ]
/usr/sbin/rcgrpwise start MTA8
echo "MTA8 on" `hostname` "was restarted at" `date` >> /tmp/gwstat.txt
mycount=$(($mycount + 1))

sleep 5

if [ $mycount != 0 ]
echo "MTA8 -- " `/usr/sbin/rcgrpwise status MTA8` >> /tmp/gwstat.txt
mail -s "GW08 Server Alert!" gw_alerts@domain.com < /tmp/gwstat.txt