From 9d651c1e48698ebd746a182d059291e76989601a Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 3 Jul 2020 17:45:54 -0400 Subject: [PATCH] minor fixes --- README | 3 +++ log-once | 27 ++++++++++----------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/README b/README index e7fab7e..e463d69 100644 --- a/README +++ b/README @@ -1,5 +1,8 @@ Log output, conditionally email or print it +Warning: with sysd-log-once, I've found the mail command to block for +several seconds at least. + The main documentation is availiable via --help and near the top of the bash script files which sit next to this file. diff --git a/log-once b/log-once index 8f2fafe..4a2b348 100755 --- a/log-once +++ b/log-once @@ -1,26 +1,15 @@ #!/bin/bash -# Copyright (C) 2016 Ian Kelling - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Copyright (C) 2019 Ian Kelling +# SPDX-License-Identifier: AGPL-3.0-or-later append() { cat >> "$1" } log-once() { - local cbase c log x i out file o + local cbase c log x i out file o tmp cbase=/var/local/cron-errors [[ $EUID == 0 ]] || cbase=$HOME/cron-errors - local help="Usage: log-once [OPTION]... LOG_NAME [LOG_MESSAGE] + local help="Usage: log-once [OPTION]... LOG_NAME [LOG_MESSAGE...] For cronjobs, email log on repeated failure and success after failure. @@ -65,7 +54,11 @@ state in the same directory. done fi glob="$c[0-9]*" - file=($glob); [[ $file != "$glob" ]] || file= + # file is error file indicating previous error + tmp=($glob); file="${tmp[0]}" + if [[ $file == "$glob" ]]; then + file= + fi if $log; then out=append if [[ $file ]]; then @@ -86,7 +79,7 @@ state in the same directory. fi $out $file <<<"log-once: $(date "+%A, %B %d, %r")" if [[ $2 ]]; then - $out $file <<<"$2" + $out $file <<<"$*" else for o in "${output[@]}"; do $out $file <<<"$o" -- 2.30.2