Explorar o código

Added directory check

Simply checks if the script log directory exists to suppress the "not
found" error message. Could be improved with a "friendly" user
notification in the future?
Marvin Lehmann %!s(int64=9) %!d(string=hai) anos
pai
achega
464a8bd8e0
Modificáronse 1 ficheiros con 36 adicións e 24 borrados
  1. 36 24
      lgsm/functions/core_messages.sh

+ 36 - 24
lgsm/functions/core_messages.sh

@@ -25,59 +25,71 @@ fi
 ##########
 ##########
 ## Feb 28 14:56:58 ut99-server: Monitor:
 ## Feb 28 14:56:58 ut99-server: Monitor:
 fn_script_log(){
 fn_script_log(){
-	if [ -n "${commandname}" ]; then
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ${1}" >> "${scriptlog}"
-	else
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
+	if [ -d "${scriptlogdir}" ]; then
+		if [ -n "${commandname}" ]; then
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ${1}" >> "${scriptlog}"
+		else
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
+		fi
 	fi
 	fi
 }
 }
 
 
 ## Feb 28 14:56:58 ut99-server: Monitor: PASS:
 ## Feb 28 14:56:58 ut99-server: Monitor: PASS:
 fn_script_log_pass(){
 fn_script_log_pass(){
-	if [ -n "${commandname}" ]; then
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: PASS: ${1}" >> "${scriptlog}"
-	else
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: PASS: ${1}" >> "${scriptlog}"
+	if [ -d "${scriptlogdir}" ]; then
+		if [ -n "${commandname}" ]; then
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: PASS: ${1}" >> "${scriptlog}"
+		else
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: PASS: ${1}" >> "${scriptlog}"
+		fi
 	fi
 	fi
 	exitcode=0
 	exitcode=0
 }
 }
 
 
 ## Feb 28 14:56:58 ut99-server: Monitor: FATAL:
 ## Feb 28 14:56:58 ut99-server: Monitor: FATAL:
 fn_script_log_fatal(){
 fn_script_log_fatal(){
-	if [ -n "${commandname}" ]; then
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: FATAL: ${1}" >> "${scriptlog}"
-	else
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: FATAL: ${1}" >> "${scriptlog}"
+	if [ -d "${scriptlogdir}" ]; then
+		if [ -n "${commandname}" ]; then
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: FATAL: ${1}" >> "${scriptlog}"
+		else
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: FATAL: ${1}" >> "${scriptlog}"
+		fi
 	fi
 	fi
 	exitcode=1
 	exitcode=1
 }
 }
 
 
 ## Feb 28 14:56:58 ut99-server: Monitor: ERROR:
 ## Feb 28 14:56:58 ut99-server: Monitor: ERROR:
 fn_script_log_error(){
 fn_script_log_error(){
-	if [ -n "${commandname}" ]; then
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ERROR: ${1}" >> "${scriptlog}"
-	else
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ERROR: ${1}" >> "${scriptlog}"
+	if [ -d "${scriptlogdir}" ]; then
+		if [ -n "${commandname}" ]; then
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ERROR: ${1}" >> "${scriptlog}"
+		else
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ERROR: ${1}" >> "${scriptlog}"
+		fi
 	fi
 	fi
 	exitcode=2
 	exitcode=2
 }
 }
 
 
 ## Feb 28 14:56:58 ut99-server: Monitor: WARN:
 ## Feb 28 14:56:58 ut99-server: Monitor: WARN:
 fn_script_log_warn(){
 fn_script_log_warn(){
-	if [ -n "${commandname}" ]; then
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: WARN: ${1}" >> "${scriptlog}"
-	else
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: WARN: ${1}" >> "${scriptlog}"
+	if [ -d "${scriptlogdir}" ]; then
+		if [ -n "${commandname}" ]; then
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: WARN: ${1}" >> "${scriptlog}"
+		else
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: WARN: ${1}" >> "${scriptlog}"
+		fi
 	fi
 	fi
 	exitcode=3
 	exitcode=3
 }
 }
 
 
 ## Feb 28 14:56:58 ut99-server: Monitor: INFO:
 ## Feb 28 14:56:58 ut99-server: Monitor: INFO:
 fn_script_log_info(){
 fn_script_log_info(){
-	if [ -n "${commandname}" ]; then
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: INFO: ${1}" >> "${scriptlog}"
-	else
-		echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: INFO: ${1}" >> "${scriptlog}"
+	if [ -d "${scriptlogdir}" ]; then
+		if [ -n "${commandname}" ]; then
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: INFO: ${1}" >> "${scriptlog}"
+		else
+			echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: INFO: ${1}" >> "${scriptlog}"
+		fi
 	fi
 	fi
 }
 }