consolelog 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin consolelog
  4. #
  5. # Description : Set the kernel log level for the console
  6. #
  7. # Authors : Dan Nicholson - dnicholson@linuxfromscratch.org
  8. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  9. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  12. #
  13. # Notes : /proc must be mounted before this can run
  14. #
  15. ########################################################################
  16. ### BEGIN INIT INFO
  17. # Provides: consolelog
  18. # Required-Start:
  19. # Should-Start:
  20. # Required-Stop:
  21. # Should-Stop:
  22. # Default-Start: S
  23. # Default-Stop:
  24. # Short-Description: Sets the console log level.
  25. # Description: Sets the console log level.
  26. # X-LFS-Provided-By: LFS
  27. ### END INIT INFO
  28. . /lib/boot/functions
  29. # set the default loglevel
  30. LOGLEVEL=7
  31. [ -r /etc/sysconfig/console ] && . /etc/sysconfig/console
  32. case "${1}" in
  33. start)
  34. case "$LOGLEVEL" in
  35. [1-8])
  36. boot_mesg "Setting the console log level to ${LOGLEVEL}..."
  37. dmesg -n $LOGLEVEL
  38. evaluate_retval
  39. ;;
  40. *)
  41. boot_mesg "Console log level '${LOGLEVEL}' is invalid" ${FAILURE}
  42. echo_failure
  43. ;;
  44. esac
  45. ;;
  46. status)
  47. # Read the current value if possible
  48. if [ -r /proc/sys/kernel/printk ]; then
  49. read level line < /proc/sys/kernel/printk
  50. else
  51. boot_mesg "Can't read the current console log level" ${FAILURE}
  52. echo_failure
  53. fi
  54. # Print the value
  55. if [ -n "$level" ]; then
  56. ${ECHO} -e "${INFO}The current console log level is ${level}${NORMAL}"
  57. fi
  58. ;;
  59. *)
  60. echo "Usage: ${0} {start|status}"
  61. exit 1
  62. ;;
  63. esac
  64. # End consolelog