Mike Frysinger | bcb6dd9 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | usage() { |
| 4 | ( |
| 5 | echo "Usage: $0 <board IP> [board port]" |
| 6 | echo "" |
| 7 | echo "If port is not specified, '6666' will be used" |
| 8 | [ -z "$*" ] && exit 0 |
| 9 | echo "" |
| 10 | echo "ERROR: $*" |
| 11 | exit 1 |
| 12 | ) 1>&2 |
| 13 | exit $? |
| 14 | } |
| 15 | |
| 16 | while [ -n "$1" ] ; do |
| 17 | case $1 in |
| 18 | -h|--help) usage;; |
| 19 | --) break;; |
| 20 | -*) usage "Invalid option $1";; |
| 21 | *) break;; |
| 22 | esac |
| 23 | shift |
| 24 | done |
| 25 | |
| 26 | ip=$1 |
| 27 | port=${2:-6666} |
| 28 | |
| 29 | if [ -z "${ip}" ] || [ -n "$3" ] ; then |
| 30 | usage "Invalid number of arguments" |
| 31 | fi |
| 32 | |
| 33 | for nc in netcat nc ; do |
Mike Frysinger | 7709318 | 2009-09-09 12:20:20 -0400 | [diff] [blame^] | 34 | type ${nc} >/dev/null 2>&1 && break |
Mike Frysinger | bcb6dd9 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 35 | done |
| 36 | |
| 37 | trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15 |
| 38 | echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T" |
| 39 | |
| 40 | stty -icanon -echo intr ^T |
Mike Frysinger | 7709318 | 2009-09-09 12:20:20 -0400 | [diff] [blame^] | 41 | ( |
| 42 | while ${nc} -u -l -p ${port} < /dev/null ; do |
| 43 | : |
| 44 | done |
| 45 | ) & |
| 46 | pid=$! |
| 47 | ${nc} -u ${ip} ${port} |
| 48 | kill ${pid} 2>/dev/null |