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:
shuki
2026-03-06 07:12:18 +02:00
parent 604437bed2
commit 279b05b5e4

View File

@@ -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%).