netconsole 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. usage() {
  3. (
  4. echo "Usage: $0 <board-IP> [board-port [board-in-port]]"
  5. echo ""
  6. echo "If port is not specified, '6666' will be used"
  7. [ -z "$*" ] && exit 0
  8. echo ""
  9. echo "ERROR: $*"
  10. exit 1
  11. ) 1>&2
  12. exit $?
  13. }
  14. while [ -n "$1" ] ; do
  15. case $1 in
  16. -h|--help) usage;;
  17. --) break;;
  18. -*) usage "Invalid option $1";;
  19. *) break;;
  20. esac
  21. shift
  22. done
  23. ip=$1
  24. board_out_port=${2:-6666}
  25. board_in_port=${3:-${board_out_port}}
  26. echo Board out port: ${board_out_port}
  27. echo Board in port: ${board_in_port}
  28. if [ -z "${ip}" ] || [ -n "$4" ] ; then
  29. usage "Invalid number of arguments"
  30. fi
  31. for nc in netcat nc ; do
  32. type ${nc} >/dev/null 2>&1 && break
  33. done
  34. trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15
  35. echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
  36. stty -icanon -echo intr ^T
  37. (
  38. if type ncb 2>/dev/null ; then
  39. # see if ncb is in $PATH
  40. exec ncb ${board_out_port}
  41. elif [ -x ${0%/*}/ncb ] ; then
  42. # maybe it's in the same dir as the netconsole script
  43. exec ${0%/*}/ncb ${board_out_port}
  44. else
  45. # blah, just use regular netcat
  46. while ${nc} -u -l -p ${board_out_port} < /dev/null ; do
  47. :
  48. done
  49. fi
  50. ) &
  51. pid=$!
  52. ${nc} -u ${ip} ${board_in_port}
  53. kill ${pid} 2>/dev/null