blob: c8109bb09569ab770aa26be63fad94433b97fc09 [file] [log] [blame]
Mike Frysingerbcb6dd92008-12-09 23:20:31 -05001#!/bin/sh
2
3usage() {
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
16while [ -n "$1" ] ; do
17 case $1 in
18 -h|--help) usage;;
19 --) break;;
20 -*) usage "Invalid option $1";;
21 *) break;;
22 esac
23 shift
24done
25
26ip=$1
27port=${2:-6666}
28
29if [ -z "${ip}" ] || [ -n "$3" ] ; then
30 usage "Invalid number of arguments"
31fi
32
33for nc in netcat nc ; do
Mike Frysinger9914be92009-09-09 12:20:20 -040034 type ${nc} >/dev/null 2>&1 && break
Mike Frysingerbcb6dd92008-12-09 23:20:31 -050035done
36
37trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15
38echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
39
40stty -icanon -echo intr ^T
Mike Frysinger9914be92009-09-09 12:20:20 -040041(
Mike Frysingerc73fdc22009-09-09 12:20:21 -040042if type ncb 2>/dev/null ; then
43 # see if ncb is in $PATH
44 exec ncb ${port}
45
46elif [ -x ${0%/*}/ncb ] ; then
47 # maybe it's in the same dir as the netconsole script
48 exec ${0%/*}/ncb ${port}
49
50else
51 # blah, just use regular netcat
52 while ${nc} -u -l -p ${port} < /dev/null ; do
53 :
54 done
55fi
Mike Frysinger9914be92009-09-09 12:20:20 -040056) &
57pid=$!
58${nc} -u ${ip} ${port}
59kill ${pid} 2>/dev/null