From 37be0b478a65638dd0c1c78f65ae0cd7247f0bd8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 9 May 2017 12:18:42 +0200 Subject: [PATCH] update shell log for truncate script --- lib/file/truncate | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/file/truncate b/lib/file/truncate index 7dd4030..8528cb0 100755 --- a/lib/file/truncate +++ b/lib/file/truncate @@ -11,20 +11,23 @@ source $__DIR__/../../lib/include/bash/func; # (1) If argument missing # if [ $# -lt 2 ]; then - echo 127; - exit 127; + slog "Missing argument(s)" "file:truncate" "update"; + echo 128; + exit 128; fi; # (2) Check argument #1 # if [ ! -e "$DATA_DIR/$1" ]; then - echo 127; - exit 127; + slog "Data file '$1' does not exist in '$DATA_DIR'" "file:truncate" "update"; + echo 129; + exit 129; fi; # (3) Check number of lines to truncate # if [ $2 -gt $(wc -l "$DATA_DIR/$1" | awk '{print $1}') ]; then - echo 127; - exit 127; + slog "Failure: asked to remove $2 lines out of $(wc -l "$DATA_DIR/$1") lines" "file:truncate" "update"; + echo 130; + exit 130; fi; @@ -37,5 +40,6 @@ incr=$(expr $2 + 1); tail -n +$incr "$DATA_DIR/$1" | tee "$DATA_DIR/$1" > /dev/null; +slog "Succesfully truncated $2 lines" "file:truncate" "update"; echo 0; exit 0;