cat >> "$1"
}
log-once() {
- local cbase c log x i out file
+ local cbase c log x i out file o
cbase=/var/local/cron-errors
[[ $EUID == 0 ]] || cbase=$HOME/cron-errors
local help="Usage: log-once [OPTION]... LOG_NAME [LOG_MESSAGE]
# read stdin for anything which is not just a newline
elif [[ ! -t 0 ]]; then
while read -r x; do
- output+=( $x )
+ output+=( "$x" )
[[ $x ]] && log=true
done
fi
fi
else
file=${c}1
+ if (( errors == 1 )); then
+ out="tee -a"
+ fi
fi
$out $file <<<"log-once: $(date "+%A, %B %d, %r")"
if [[ $2 ]]; then
$out $file <<<"$2"
else
- $out $file <<<"${output[@]}"
+ for o in "${output[@]}"; do
+ $out $file <<<"$o"
+ done
$out $file
fi
return 0