Skip to content

Commit

Permalink
Merge pull request #159 from NiceGuyIT/issue-158
Browse files Browse the repository at this point in the history
Fix #158: collect_fake_json.sh
  • Loading branch information
NiceGuyIT authored Oct 25, 2023
2 parents d20ab77 + 4fe758e commit 25f2581
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions collect_fake_json.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#! /bin/bash

for device in $(smartctl --scan | awk '{ print $1}')
do
smartctl --json --xall $device | jq > debug/$(basename $device).json
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# The original script used --xall but that doesn't work
# This matches the command in readSMARTctl()
smartctl_args="--json --info --health --attributes --tolerance=verypermissive --nocheck=standby --format=brief --log=error"

[[ ! -d "${script_dir}/debug" ]] && mkdir --parents "${script_dir}/debug"

if command -v jq >/dev/null; then
devices=$(smartctl --scan --json | jq --raw-output '.devices[].name')
elif command -v yq >/dev/null; then
devices=$(smartctl --scan --json | yq --unwrapScalar '.devices[].name')
elif command -v awk >/dev/null; then
devices=$(smartctl --scan | awk '{ print($1) }')
else
devices=$(smartctl --scan | cut -d ' ' -f 1)
fi

for device in $devices; do
echo "Collecting data for '${device}'"
# shellcheck disable=SC2086
sudo smartctl $smartctl_args "${device}" > "${script_dir}/debug/$(basename "${device}").json"
done

0 comments on commit 25f2581

Please sign in to comment.