Added debug extension (#155)

This commit is contained in:
bg-wa 2018-01-09 14:22:29 -08:00 committed by Sebastian Kinne
parent f8a442e66d
commit 650772e9e4

View File

@ -0,0 +1,40 @@
#!/bin/bash
################################################################################
# Allow Debugging messages written to: "/root/udisk/debug/[session].txt"
# on the BashBunny
#
# How this works?
# 1) Example Command: DEBUG "switch-1-debug" "Hello from debug extension!"
# 2) After bashing, text can be read at: "/root/udisk/debug/[session].txt"
# on the BashBunny
################################################################################
function DEBUG() {
session = $1
message = $2
init_debug
debug_log
timestamp () {
echo "$(date +"%Y-%m-%d_%H-%M-%S")"
}
init_debug () {
DEBUG_FILE="/root/udisk/debug/$(session).txt"
if [ ! -d "/root/udisk/debug/" ]; then
mkdir /root/udisk/debug/
fi
if [ ! -f "/root/udisk/debug/${DEBUG_FILE}" ]; then
touch "${DEBUG_FILE}"
echo "$(timestamp): DEBUG STARTED" >> "${DEBUG_FILE}"
fi
}
debug_log () {
echo "$(timestamp): $(message)" >> "${DEBUG_FILE}"
}
}
export -f DEBUG