Fix disk usage parsing — use grep instead of df --output
df --output=pcent is not available on all systems. Use grep -oP to extract the percentage field from standard df output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -294,22 +294,23 @@ get_target_remotes() {
|
|||||||
# Returns 0 (unknown) on unsupported remote types.
|
# Returns 0 (unknown) on unsupported remote types.
|
||||||
remote_disk_usage_pct() {
|
remote_disk_usage_pct() {
|
||||||
local base="${REMOTE_BASE:-/}"
|
local base="${REMOTE_BASE:-/}"
|
||||||
local df_out=""
|
local df_line=""
|
||||||
case "${REMOTE_TYPE:-ssh}" in
|
case "${REMOTE_TYPE:-ssh}" in
|
||||||
ssh)
|
ssh)
|
||||||
df_out=$(remote_exec "df --output=pcent '$base' 2>/dev/null | tail -1" 2>/dev/null) || return 1
|
df_line=$(remote_exec "df '$base' 2>/dev/null | tail -1") || return 1
|
||||||
;;
|
;;
|
||||||
local)
|
local)
|
||||||
df_out=$(df --output=pcent "$base" 2>/dev/null | tail -1) || return 1
|
df_line=$(df "$base" 2>/dev/null | tail -1) || return 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "0"
|
echo "0"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# Strip whitespace and % sign
|
# Extract the percentage field (e.g. "73%") — grep for number followed by %
|
||||||
df_out="${df_out// /}"
|
local pct_raw
|
||||||
echo "${df_out%%%}"
|
pct_raw=$(echo "$df_line" | grep -oP '[0-9]+%' | head -1) || return 1
|
||||||
|
echo "${pct_raw%%%}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check remote disk space. Fail if usage >= threshold (default 95%).
|
# Check remote disk space. Fail if usage >= threshold (default 95%).
|
||||||
|
|||||||
Reference in New Issue
Block a user