consolelog 1.8 KB

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