Created
January 15, 2016 00:12
-
-
Save jigpu/948f7bc6202f45ea9d42 to your computer and use it in GitHub Desktop.
Setup the netconsole module to send kernel logs to a remote machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
######## | |
# Script to easily enable netconsole and change kernel verbosity | |
# | |
# See http://elinux.org/Debugging_py_printing | |
# | |
set -e | |
declare -A VERBOSITY | |
VERBOSITY[0]=KERN_EMERG | |
VERBOSITY[1]=KERN_ALERT | |
VERBOSITY[2]=KERN_CRIT | |
VERBOSITY[3]=KERN_ERR | |
VERBOSITY[4]=KERN_WARNING | |
VERBOSITY[5]=KERN_NOTICE | |
VERBOSITY[6]=KERN_INFO | |
VERBOSITY[7]=KERN_DEBUG | |
LEVEL=7 | |
ERR="" | |
if [[ $# -eq 0 ]]; then ERR="Missing required arguments."; fi | |
if [[ $# -ge 1 ]]; then IP=$1; fi | |
if [[ $# -ge 2 ]]; then LEVEL=$2; fi | |
if [[ $# -ge 3 ]]; then ERR="Too many arguments."; fi | |
if [[ ! " ${!VERBOSITY[@]} " =~ " $LEVEL " ]]; then | |
ERR="Unknown verbosity level." | |
fi | |
if [[ "x$ERR" != "x" ]]; then | |
echo "Error: $ERR" | |
echo "Usage: $(basename $0) <ip address> [verbosity]" | |
echo | |
echo "Accepted numeric verbosity levels are:" | |
for i in "${!VERBOSITY[@]}"; do | |
echo " $i (${VERBOSITY[$i]})" | |
done | |
exit 1 | |
fi | |
echo "Sending console output via UDP to $IP:6666" | |
modprobe netconsole netconsole=@/,@${IP}/ | |
echo "Increasing console verbosity to $LEVEL (${VERBOSITY[$LEVEL]})" | |
echo $LEVEL > /proc/sys/kernel/printk | |
echo "Please run \`netcat -u -l 6666\` on the target machine at $IP now." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment