D.5.
/etc/rc.d/init.d/consolelog
#!/bin/sh
########################################################################
# Begin consolelog
#
# Description : Set the kernel log level for the console
#
# Authors : Dan Nicholson - [email protected]
# Gerard Beekmans - [email protected]
# DJ Lucas - [email protected]
# Update : Bruce Dubbs - [email protected]
#
# Version : LFS 7.0
#
# Notes : /proc must be mounted before this can run
#
########################################################################
### BEGIN INIT INFO
# Provides: consolelog
# Required-Start:
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Sets the console log level.
# Description: Sets the console log level.
# X-LFS-Provided-By: LFS
### END INIT INFO
. /lib/lsb/init-functions
# set the default loglevel if needed
LOGLEVEL=${LOGLEVEL:-7}
[ -r /etc/sysconfig/console ] && . /etc/sysconfig/console
case "${1}" in
start)
case "$LOGLEVEL" in
[1-8])
log_info_msg "Setting the console log level to ${LOGLEVEL}..."
dmesg -n $LOGLEVEL
evaluate_retval
exit 0
;;
*)
log_failure_msg "Console log level '${LOGLEVEL}' is invalid"
exit 1
;;
esac
;;
status)
# Read the current value if possible
if [ -r /proc/sys/kernel/printk ]; then
read level line < /proc/sys/kernel/printk
else
log_failure_msg "Can't read the current console log level"
exit 1
fi
# Print the value
if [ -n "$level" ]; then
log_info_msg "The current console log level is ${level}\n"
exit 0
fi
;;
*)
echo "Usage: ${0} {start|status}"
exit 1
;;
esac
# End consolelog