netconsole 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 socat 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 [ "${nc}" = "socat" ] ; then
  42. # socat does support broadcast
  43. while ${nc} STDIO "UDP4-LISTEN:${board_out_port}"; do :; done
  44. elif [ -x ${0%/*}/ncb ] ; then
  45. # maybe it's in the same dir as the netconsole script
  46. exec ${0%/*}/ncb ${board_out_port}
  47. else
  48. # blah, just use regular netcat
  49. while ${nc} -u -l -p ${board_out_port} < /dev/null ; do
  50. :
  51. done
  52. fi
  53. ) &
  54. pid=$!
  55. if [ "${nc}" = "socat" ] ; then
  56. ${nc} - "UDP4:${ip}:${board_in_port}"
  57. else
  58. ${nc} -u ${ip} ${board_in_port}
  59. fi
  60. kill ${pid} 2>/dev/null