From 0eab3624e8971c191c9024d93542f7227514c7fc Mon Sep 17 00:00:00 2001 From: Cyberes Date: Tue, 17 Sep 2024 18:56:27 -0600 Subject: [PATCH] check_systemd_service: handle nfs mounts --- check_systemd_service.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/check_systemd_service.sh b/check_systemd_service.sh index d5038e7..c1332f8 100755 --- a/check_systemd_service.sh +++ b/check_systemd_service.sh @@ -77,18 +77,23 @@ current_time=$(date +%s) start_time_diff_perf="" end_time_diff_perf="" -if [ -n "$start_time" ] && [ "$start_time" != "n/a" ]; then +start_time_str="" +if [ -n "$start_time" ] && [ "$start_time" != "n/a" ] && [ -z "$start_time" ]; then start_time_diff=$((current_time - $(date -d "$start_time" +%s))) start_time_diff_perf="| uptime=${start_time_diff}s" + start_time_str=" Started at $start_time." fi -if [ -n "$end_time" ] && [ "$end_time" != "n/a" ]; then + +end_time_str="" +if [ -n "$end_time" ] && [ "$end_time" != "n/a" ] && [ -z "$end_time" ]; then end_time_diff=$((current_time - $(date -d "$end_time" +%s))) end_time_diff_perf="| downtime=${end_time_diff}s" + end_time_str=" Exited at $end_time." fi if [ "$IS_TIMER" = true ] && { [ "$substate" = "exited" ] || [ "$active" = "inactive" ]; }; then - echo "OK - $UNIT_NAME is active and exited (returned $exit_code) and enabled. Exited at $end_time. $end_time_diff_perf" + echo "OK - $UNIT_NAME is active and exited (returned $exit_code) and enabled.$end_time_str $end_time_diff_perf" else - echo "OK - $UNIT_NAME is active and enabled. Started at $start_time. $start_time_diff_perf" + echo "OK - $UNIT_NAME is active and enabled.$start_time_str $start_time_diff_perf" fi exit 0