From f9d0b073063af262d468ec90dc8f5838a74a9f58 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Mon, 5 Sep 2016 13:49:42 +0100 Subject: [PATCH] log output to a file if $cloud is defined This eliminates the risk of losing crucial debug output in a long mkcloud run because you forgot to redirect to a file and the terminal/screen/tmux scrollback buffer wasn't big enough. If the 'help' argument is passed, it is assumed that logging is not required. Otherwise, a warning is emitted if logging is not possible due to $cloud not being set. Closes #1191. --- scripts/mkcloud | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/mkcloud b/scripts/mkcloud index f2120e9699..e54b589802 100755 --- a/scripts/mkcloud +++ b/scripts/mkcloud @@ -15,6 +15,15 @@ # 2. This tool relies on the script qa_crowbarsetup.sh # 3. Please 'export' environment variables according to your needs. +if [ -n "$cloud" ]; then + : ${log_dir:=/var/log/mkcloud/$cloud} + mkdir -p "$log_dir" + log_file=$log_dir/`date -Iseconds`.log + exec > >(tee -ia $log_file) + exec 2> >(tee -ia $log_file >&2) +elif ! [[ " $@ " =~ " help " ]]; then + echo "WARNING: \$cloud not set, so won't log to a file" >&2 +fi if [[ $debug_mkcloud = 1 ]] ; then set -x