make log_rotation.sh safer
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if [ "$1" = "" ]; then
|
if [ "$1" == "" ]; then
|
||||||
/bin/echo "no file"
|
echo "no file"
|
||||||
elif [ "$1" = "/tmp/rsyslog/root_file" ]; then
|
elif [ "$1" = "/tmp/rsyslog/root_file" ]; then
|
||||||
/bin/rm -f "$1"
|
/bin/rm -f "$1"
|
||||||
else
|
else
|
||||||
new_file=$1"_"`/bin/date '+20%y_%m_%d'`
|
new_file="${1}_$(/bin/date '+20%y_%m_%d')"
|
||||||
i=0
|
i=0
|
||||||
test_file=$new_file
|
test_file="$new_file"
|
||||||
while [ -f $test_file ]
|
while [ -f "$test_file" ]
|
||||||
do
|
do
|
||||||
i=$(($i+1))
|
i=$(($i+1))
|
||||||
test_file=$new_file"."$i
|
test_file="${new_file}.${i}"
|
||||||
done
|
done
|
||||||
|
|
||||||
/bin/mv -f "$1" $test_file
|
/bin/mv -f "$1" "$test_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user