#!/bin/sh # replace database/tw.db_host.gz with tw.db_host_new.gz # $0 [-a] or $0 host1 host2 .... # # (c) Yunliang Yu #set -x ####IFS=space,tab,newline## IFS=" " PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/etc:/etc/ssh/bin:$HOME/bin export IFS PATH umask 077 ########################### cd databases || { echo "Can't cd to databases directory"; exit 1 } tw_new_list=; if test $# -eq 0; then echo "Usage: $0 [-a] or $0 host1 host2 ...."; exit 1; elif test $1 = "-a"; then echo -n "Replace ALL tw.db_host.gz with tw.db_host_new.gz? [y] "; read tmp case $tmp in ""|y*) tw_new_list="`ls tw.db_*_new.gz 2>/dev/null`";; esac else echo -n "Replace given tw.db_host.gz with tw.db_host_new.gz? [y] "; read tmp case $tmp in ""|y*) for k in $@; do i="tw.db_${k}_new.gz" tw_new_list="$tw_new_list $i"; done ;; esac fi today=`date +%d`; # today's or the latest? No=0; for i in $tw_new_list; do j="`echo $i|sed 's/_new.gz/.gz/'`"; if test ! -s $i; then echo "+++ $i not exist or size zero +++" continue fi Up=1; if test $No -eq 0; then log="logs/`echo $j|sed 's/tw.db_//'|sed 's/.gz//'`_$today"; echo -n "**** View $log? (y/n/N/q)[y] "; read tmp; case $tmp in ""|y*) less ../$log echo -n "*** Update $j (y/n)[y] "; read tmp1; case $tmp1 in n*) Up=0;; esac ;; N*) No=1;; q*) exit 0;; esac; fi if test $Up -eq 1; then if test -f $j; then mv $j $j-x; fi mv $i $j echo "=== $j ==== updated" else echo "=== $j ==== NOT updated" fi done