netconsole 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. usage() {
  3. (
  4. echo "Usage: $0 <board IP> [board 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. port=${2:-6666}
  25. if [ -z "${ip}" ] || [ -n "$3" ] ; then
  26. usage "Invalid number of arguments"
  27. fi
  28. for nc in netcat nc ; do
  29. type ${nc} >/dev/null 2>&1 && break
  30. done
  31. trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15
  32. echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
  33. stty -icanon -echo intr ^T
  34. (
  35. if type ncb 2>/dev/null ; then
  36. # see if ncb is in $PATH
  37. exec ncb ${port}
  38. elif [ -x ${0%/*}/ncb ] ; then
  39. # maybe it's in the same dir as the netconsole script
  40. exec ${0%/*}/ncb ${port}
  41. else
  42. # blah, just use regular netcat
  43. while ${nc} -u -l -p ${port} < /dev/null ; do
  44. :
  45. done
  46. fi
  47. ) &
  48. pid=$!
  49. ${nc} -u ${ip} ${port}
  50. kill ${pid} 2>/dev/null