I create a bash script that check the connection to an host with telnet. That's the core code:
telnet $X 2404 < $TEST &>/dev/null
if [ $? -ne 0 ] ; then
echo -n "$X " >> $LOG_FILE
echo "OFFLINE <---" >> $LOG_FILE
else
echo -n "$X " >> $LOG_FILE
echo "ONLINE" >> $LOG_FILE
fi
I want to have three separated message:
- ONLINE for telnet estabilished
- OFFLINE for connection refused
- TIMEOUT for connection timeout
The problem is that both "connection refused" and "connection timeout" return an exit status 1.
Any idea? Thanks to all.