From: R. Steve McKown Date: Fri, 18 Jan 2013 01:18:01 +0000 (-0700) Subject: bpcdump: capture all log output X-Git-Url: https://oss.titaniummirror.com/gitweb?p=ovzbpc.git;a=commitdiff_plain;h=06e2c63de5e45e98a2196c4213eebbea4fe9e91f 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. --- 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"