#!/bin/sh SOCAT=/usr/bin/socat SLEEP=$((10*60)) TRIES=0 while true; do if $SOCAT TCP:myserver.example.com:12345 TCP4:localhost:22; then echo good socat exit: $?, trying again TRIES=100 else RET=$? if [ "$TRIES" -gt 0 ]; then TRIES=$((TRIES-1)); sleep 5; echo trying $TRIES more times continue; fi; echo socat return code: $RET, sleeping for $SLEEP sec sleep $SLEEP fi done # > /mnt/usb/socat.log 2>&1