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.
#!/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.
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
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"