From c2e54cae532192f60e4be77b1a655e546736fe08 Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 7 Aug 2014 03:25:32 +1000 Subject: [PATCH] script to convert ckdb2014*log filenames to UTC --- src/relog.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 src/relog.sh diff --git a/src/relog.sh b/src/relog.sh new file mode 100755 index 00000000..e90c5ec0 --- /dev/null +++ b/src/relog.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# +p1() +{ + while true ; do + read line + if [ "$?" != "0" ] ; then + return + fi +# echo "$line" + if [ ! -f "$line" ] ; then + echo "ERR: file not found: '$line'" + else + base="`echo "$line" | sed -e "s/\(^.*ckdb2014\).*$/\1/"`" + rest="`echo "$line" | sed -e "s/^.*ckdb2014\(.*\).log$/\1/"`" + m="${rest:0:2}" + d="${rest:2:2}" + h="${rest:4:2}" + tz="`date -d"2014-$m-$d 00:00" +%z`" + fix="`date -u -d"2014-$m-$d $h:00 $tz" +"%m%d%H"`" + echo "mv '$line' '$base$fix.log2'" + mv "$line" "$base$fix.log2" + fi + done +} +# +p2() +{ + while true ; do + read line + if [ "$?" != "0" ] ; then + return + fi + nn="${line/log2/log}" + echo "mv '$line' '$nn'" + mv "$line" "$nn" + done +} +# +if [ "$1" = "/" ] ; then + dir="$1" +else + dir="${1%%/}" +fi +# +ls $dir/ckdb20140*.log | p1 +ls $dir/ckdb20140*.log2 | p2