Alex Flores b37aed0edc fixes debug extention (#312)
- resolve sytax errors with variable declarations
 - resolve misuse of command substition / variabl dereferencing
 - internal functions were being called before being declared
 - remove superfluous file existence checks
2018-01-24 06:12:30 +11:00

28 lines
820 B
Bash

#!/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
timestamp () {
echo "$(date +"%Y-%m-%d_%H-%M-%S")"
}
mkdir -p /root/udisk/debug/
debug_file="/root/udisk/debug/${session}.txt"
[[ -f "${debug_file}" ]] || echo "$(timestamp): DEBUG STARTED" >> "${debug_file}"
echo "$(timestamp): ${message}" >> ${debug_file}
}
export -f DEBUG