I'm kinda a newbie to programming, so I'll apologize in advance. I'm trying to write a bash script that will go out and test my servers and make sure they are still happily working away. In the event the are not working as I think they should I want the script to call my pager. (Pager script works fine btw.)
I'm coming into problems in more ways than one. After I have connected to the remote service I can't figure out how to exit from the telnet session.
I.E. The mail server expects a response. HELO response. I just want to quit and grep the session. (See below)
Secondly I seem to be getting an EOF (unexpected end of file) error message after trying to execute this script. I've looked over the syntax and I am just so new to this I can’t see what I’ve done wrong.
Any help and guidance would be much appreciated.
-------Begin Script-------
#!/bin/sh
#List of Servers to Check
#Insert spaces to separate multiple entries
EMAIL="192.168.1.10"
DNS="192.168.1.5"
ROUTER="192.168.1.1 192.168.1.2"
#For Every Email value telnet to port 25 and make sure everything is normal
for SYS in $EMAIL; do CHECKMAIL=`telnet $SYS 25 | grep -o "Connected"`
if [ $CHECKMAIL -ne "Connected" ] ; then
/PAGER/911dial.sh
fi
#For every DNS server check to see if it can resolve
www.google.com
for SYS2 in $DNS; do DNSLOOKUP=`dig @$SYS2
www.google.com | grep -o "answer"`
if [ $DNSLOOKUP -ne "answer" ] ; then
/PAGER/911dial.sh
fi
#Telnet to routers and double check they are active VIA Inband connection
for SYS3 in $ROUTER; do TELNET=`telnet $SYS3 | grep -o "Password:"`
if [ $TELNET -ne "Password:" ] ; then
/PAGER/911dial.sh
fi
done
#End of Critical Service Check
-------End Script-------