From cf910bc400aee28382196d828ed16a582f8bffc8 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Fri, 2 Mar 2012 08:07:29 -0800 Subject: [PATCH] Update safeguards lib in pt-stalk re bug 940503. --- bin/pt-stalk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/pt-stalk b/bin/pt-stalk index 605632ba..86c59367 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -517,9 +517,10 @@ check_disk_space() { local min_free_pct="${3:-0}" local bytes_margin="${4:-0}" - local used_bytes=$(cat "$file" | awk '/^\//{printf("%d",$3 * 1024)}'); - local free_bytes=$(cat "$file" | awk '/^\//{printf("%d",$4 * 1024)}'); - local pct_used=$(cat "$file" | awk '/^\//{print $5}' | sed -e 's/%//g'); + + local used_bytes=$(perl -ane 'm!^/! && print $F[2] * 1024' "$file") + local free_bytes=$(perl -ane 'm!^/! && print $F[3] * 1024' "$file") + local pct_used=$(perl -ane 'm!^/! && print ($F[4] =~ m/(\d+)/)' "$file") local pct_free=$((100 - $pct_used)) local real_free_bytes=$free_bytes @@ -528,7 +529,7 @@ check_disk_space() { if [ $bytes_margin -gt 0 ]; then used_bytes=$(($used_bytes + $bytes_margin)) free_bytes=$(($free_bytes - $bytes_margin)) - pct_used=$(awk "BEGIN { printf(\"%d\", ($used_bytes/($used_bytes + $free_bytes)) * 100) }") + pct_used=$(perl -e "print int(($used_bytes/($used_bytes + $free_bytes)) * 100)") pct_free=$((100 - $pct_used)) fi