I've been using this old script for some time and almost forgot about it until the other day i became aware of its limitations. Because of the net slowing down to a crawl and the ssh handshake requiring almost 40 seconds to complete, i found out that it could not tell wether the ssh tunnel was ready or not. It could just simply detect (thanks to the ssh return value) wether ssh failed or not.
Code:
machine=mach001
if [[ $1 != "" ]]; then
labmachine=$1
fi
echo "Connecting to: $labmachine"
ssh -2N $USER@$machine.my.domain.tld -L 1190:news.my.domain.tld:119 & sshpid=$!
retval=$?
if [[ $retval != 0 ]]; then
notify-send -t 5 -i $iconfolder/messagebox_warning.png "SSH FAILED" "Exit code $retval"
exit 1
fi
sleep 3
thunderbird
kill $sshpid
retval=$?
if [[ $retval != 0 ]]; then
notify-send -t 5 "Kill failed."
exit 1
fi
What's the proper way to make the script wait for the tunnel to be correctly established?
Using -v and grepping for "Entering interactive session"??
