Enhance logging in runtest.sh by implementing session logging and ensuring proper script execution flow
This commit is contained in:
parent
8224deaba1
commit
b810c93e29
1 changed files with 13 additions and 7 deletions
20
runtest.sh
20
runtest.sh
|
@ -2,13 +2,23 @@
|
|||
|
||||
set -uo pipefail
|
||||
trap 'echo "[✖] Execution halted at line $LINENO. Please consult your nearest bash therapist." >&2' ERR
|
||||
trap 'echo "[✌️] Script exited cleanly. Have a burrito." >&2' EXIT
|
||||
|
||||
IFS=$'\n\t'
|
||||
|
||||
# === Start logging with 'script' safely ===
|
||||
if [ -z "${SCRIPT_LOG_STARTED:-}" ]; then
|
||||
export SCRIPT_LOG_STARTED=1
|
||||
BOOT_ID=$(cat /proc/sys/kernel/random/boot_id)
|
||||
LOG_FILE="${HOME}/${BOOT_ID}-session.log"
|
||||
echo "[+] Starting session logging to $LOG_FILE"
|
||||
exec script -q "$LOG_FILE" --return --flush --command "$0"
|
||||
fi
|
||||
|
||||
# === Now start your real script ===
|
||||
source settings.env
|
||||
|
||||
EMAIL_BODY=${EMAIL_BODY:-"Test $BOOT_ID completed successfully. Please find the attached files and collect the probe."}
|
||||
|
||||
# (redefine BOOT_ID, TEST_FILE, etc after reloading settings.env if needed)
|
||||
BOOT_ID=$(cat /proc/sys/kernel/random/boot_id)
|
||||
TEST_FILE="${HOME}/${BOOT_ID}-speedtest.csv"
|
||||
ENRICHED_FILE="${TEST_FILE%.csv}+rf.csv"
|
||||
|
@ -16,8 +26,6 @@ SSID_METRICS_FILE="${ENRICHED_FILE%.csv}-ssid-metrics.csv"
|
|||
FAILURE_LOG="${TEST_FILE%.csv}-failures.log"
|
||||
SCRIPT_START=$(date +%s)
|
||||
|
||||
script "${TEST_FILE%.csv}-script.log"
|
||||
|
||||
log() {
|
||||
echo "[+] $*" >&2
|
||||
}
|
||||
|
@ -31,7 +39,7 @@ die() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
[ -z "$RECIPIENT" ] && die "Please set the RECIPIENT variable in settings.env."
|
||||
[ -z "${RECIPIENT:-}" ] && die "Please set the RECIPIENT variable in settings.env."
|
||||
|
||||
log "Test file: $TEST_FILE"
|
||||
log "Enriched file: $ENRICHED_FILE"
|
||||
|
@ -202,5 +210,3 @@ fi
|
|||
sudo kill "$SUDO_KEEPALIVE_PID"
|
||||
SCRIPT_END=$(date +%s)
|
||||
log "Full test cycle completed in $((SCRIPT_END - SCRIPT_START)) seconds"
|
||||
|
||||
exit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue