X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=log-once;fp=log-once;h=4a2b3480e5c8dbc20771feb9df20bef5646ce008;hb=9d651c1e48698ebd746a182d059291e76989601a;hp=8f2fafeab79c16e5f879db96f836ca1e38d057c3;hpb=d05b05db1c99982622ee70186c02d54f7d5cb5f9;p=log-quiet 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"