Output to stdout

This commit is contained in:
Loïc Guégan 2024-07-04 10:56:42 +02:00
parent 61b8d1e028
commit 6b97beb464
2 changed files with 6 additions and 9 deletions

View file

@ -1,12 +1,10 @@
# System dump script
Dump various system informations into base64 encoded value and store them in a json file.
Dump various system informations into base64 encoded values and print them as json.
# Usage
Run a dump:
> ./sysdump.sh
Result is placed into `dump.json`.
Explore a dump (require `jq`)
> ./sysdump.sh dump.json

View file

@ -1,7 +1,5 @@
#!/usr/bin/env bash
OUT="./dump.json"
ensure() {
command -v "$1" >/dev/null 2>&1 || { echo >&2 "$1 not found, abort..."; exit 1; }
}
@ -18,8 +16,8 @@ dump() {
[ -z "$2" ] && return
key=$1
value=$(echo "$2"|base64 -w 0)
[ "$USE_COMMA" -eq 1 ] && echo "\"${key}\": \"${value}\"," >> "$OUT"
[ "$USE_COMMA" -eq 0 ] && echo "\"${key}\": \"${value}\"" >> "$OUT"
[ "$USE_COMMA" -eq 1 ] && echo "\"${key}\": \"${value}\","
[ "$USE_COMMA" -eq 0 ] && echo "\"${key}\": \"${value}\""
}
# Read mode
@ -41,7 +39,7 @@ ensure date
ensure find
# Start dump
echo "{" > "$OUT"
echo "{"
USE_COMMA=1
dump "date" "$(date +%s)"
dump "hostname" "$(safecmd hostname)"
@ -75,4 +73,5 @@ dump "df" "$(safecmd df -h)"
dump "boot_folder" "$(safecmd ls -al /boot/)"
USE_COMMA=0
dump "root_folder" "$(safecmd ls -al /)"
echo "}" >> "$OUT"
echo "}"