From 06e2c63de5e45e98a2196c4213eebbea4fe9e91f Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Thu, 17 Jan 2013 18:18:01 -0700 Subject: [PATCH] bpcdump: capture all log output When bpcdump starts, use a temporary file in /tmp to capture log output from the info() and error() functions. Then, which the correct home for the info file is created, move the temporary file to that name and continue along. Prior to this commit, all of the output from info() and error() prior to INFO being redefined were not also captured into the info file. --- bpcdump | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/bpcdump b/bpcdump index 0563e13..efb8456 100755 --- a/bpcdump +++ b/bpcdump @@ -19,10 +19,10 @@ VEDEV=/dev/vg0/ve$VEID VEMNT=/var/lib/vz/private/$VEID EXTFS=/media/esata unset WRITEPAR -INFO=/dev/null export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:$PATH SCRIPT_EXT="conf start stop mount umount" CONF_DIR=/etc/vz/conf +INFO=$(mktemp -q /tmp/bpcdump.XXXXX) # FUNCTIONS @@ -86,6 +86,17 @@ cleanup() # MAIN +STARTDATE=$(date) +cat > "$INFO" <<+EOF+ +Date: $STARTDATE +VEID: $VEID +Volume: $VEDEV +dd_rescue log: ddrlog +dd_rescue bad blocks: ddrbb +image file: image + ++EOF+ + trap "cleanup 1 \"termination by signal\"" SIGINT SIGTERM if [ $(whoami) != "root" ]; then @@ -185,22 +196,14 @@ if [ -d "$EXTVEIDFS" ]; then else rm -rf "$EXTVEIDFS" fi -mkdir "$EXTVEIDFS" -date > "$EXTVEIDFS/begin" -if ! cd "$EXTVEIDFS"; then - cleanup 1 "cannot change into $EXTVEIDFS directory" -fi +mkdir "$EXTVEIDFS" || cleanup 1 "cannot mkdir $EXTVEIDFS/" +cd "$EXTVEIDFS" || cleanup 1 "cannot cd into $EXTVEIDFS/" +echo "$STARTDATE" > "$EXTVEIDFS/begin" +# Move temporary INFO file to its permanent home within $EXTVEIDFS +mv "$INFO" "$EXTVEIDFS/info" || cleanup 1 "cannot mv file to $EXTVEIDFS/" INFO="$EXTVEIDFS/info" -cat > "$INFO" <<+EOF+ -Date: $(date) -VEID: $VEID -Volume: $VEDEV -dd_rescue log: ddrlog -dd_rescue bad blocks: ddrbb -image file: image -+EOF+ info "copy $VEID device $VEDEV to $EXTVEIDFS/image" time dd_rescue -Aqy 8192 -l "$EXTVEIDFS/ddrlog" -o "$EXTVEIDFS/ddrbb" \ $VEDEV "$EXTVEIDFS/image" -- 2.39.2