You can create a function to do the connect and quit for telnet like this
UID="userid"
PWD="passwd"
ip_addr=""
extelnet () {
awk '{ if(NR == 1) {
print UI
print PW
}
print $0}
END{print "quit"}' UI=$UID PW=$PSWD | \
/usr/bin/telnet | \
grep /^Connected/
}
EMAIL="1.1.1.1 2.2.2.2.2 3.3.3.3"
for ip_addr in $EMAIL
do
connected=`echo "ls" | extelent`
if [ connected -ne "Connected" ]; then
echo "ip_addr=$ip_addr not connected"
fi
done
I did not test this code, you need to check it.