netconsole 746 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 && 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. ${nc} -u -l -p ${port} < /dev/null &
  35. exec ${nc} -u ${ip} ${port}