From c6e342ea9698d5ef60c3e97f95854e1ad9b3a064 Mon Sep 17 00:00:00 2001 From: eleksir Date: Sun, 4 Sep 2016 23:50:38 +0300 Subject: [PATCH] make log_rotation.sh safer --- log_rotation.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/log_rotation.sh b/log_rotation.sh index d218fdc..67ff7e4 100755 --- a/log_rotation.sh +++ b/log_rotation.sh @@ -1,20 +1,20 @@ #!/bin/sh -if [ "$1" = "" ]; then - /bin/echo "no file" +if [ "$1" == "" ]; then + echo "no file" elif [ "$1" = "/tmp/rsyslog/root_file" ]; then /bin/rm -f "$1" else - new_file=$1"_"`/bin/date '+20%y_%m_%d'` + new_file="${1}_$(/bin/date '+20%y_%m_%d')" i=0 - test_file=$new_file - while [ -f $test_file ] + test_file="$new_file" + while [ -f "$test_file" ] do i=$(($i+1)) - test_file=$new_file"."$i + test_file="${new_file}.${i}" done - /bin/mv -f "$1" $test_file + /bin/mv -f "$1" "$test_file" fi exit 0