From 09de901d114afc157040e998ee3aacf82357d60d Mon Sep 17 00:00:00 2001 From: Katarina Durechova Date: Tue, 31 Oct 2017 09:05:29 +0100 Subject: [PATCH] Check zero size of files correctly (#487) from man test: -s FILE FILE exists and has a size greater than zero -z STRING the length of STRING is zero --- include/functions | 4 ++-- include/tests_time | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/functions b/include/functions index 87382c58..d81382d6 100644 --- a/include/functions +++ b/include/functions @@ -726,7 +726,7 @@ if [ $# -eq 0 ]; then ExitFatal "Missing parameter when calling FileIsEmpty function"; fi EMPTY=0 LogText "Test: checking if file $1 is empty" - if [ -z $1 ]; then + if [ ! -s "$1" ]; then LogText "Result: file $1 is empty" EMPTY=1 return 0 @@ -1489,7 +1489,7 @@ # Amazon EC2 if [ "${SHORT}" = "" ]; then LogText "Test: checking specific files for Amazon" - if [ -f /etc/ec2_version -a ! -z /etc/ec2_version ]; then + if [ -f /etc/ec2_version -a -s /etc/ec2_version ]; then SHORT="amazon-ec2" else LogText "Result: system not hosted on Amazon" diff --git a/include/tests_time b/include/tests_time index 05781c81..4d9dbfe5 100644 --- a/include/tests_time +++ b/include/tests_time @@ -428,7 +428,7 @@ FOUND=0 FILE="/etc/ntp/step-tickers" if [ -f ${FILE} ]; then - if [ -z ${FILE} ]; then + if [ ! -s "${FILE}" ]; then LogText "Result: ${FILE} is empty. The step-tickers contain no configured NTP servers" Display --indent 2 --text "- Checking NTP step-tickers file" --result "EMPTY FILE" --color YELLOW ReportSuggestion ${TEST_NO} "Use step-tickers file for quicker time synchronization"