2. 程式碼
#!/usr/local/bin/bash
PATH=$PATH
CHKPARA=0
if [ -n "$1" ]; then
CHKPATH="$1"
shift
else
CHKPARA=1
fi
if [ -n "$1" ]; then
SSKEYWORD="$1"
shift
else
CHKPARA=1
fi
if [ -n "$1" ]; then
SSBASE="$1"
shift
else
CHKPARA=1
fi
if [ $CHKPARA -eq 1 ]; then
echo "Usage: $0 check_path snapshot_keyword snapshot_base_path"
echo "Example: $0 /etc Weekly /SNAPSHOT/System"
exit 1
else
echo "Collect difference between $CHKPATH and $SSBASE/${SSKEYWORD}*$CHKPATH."
fi
date +"%Y/%m/%d %H:%M:%S"
LAST_DIR="/"
CHKPATH=`echo $CHKPATH | sed -e 's/\///'`
for CONF in `find $LAST_DIR$CHKPATH -type f -name '*'`
do
if [ `ls $SSBASE | grep ${SSKEYWORD} |wc -l` -lt 1 ]; then
echo "$SSBASE/${SSKEYWORD}* does not existed!"
exit 1
fi
ls -d $SSBASE/${SSKEYWORD}* | while read DIR
do
if [ -f ${LAST_DIR}${CONF} ]&&[ -f ${DIR}${CONF} ]; then
if [ $LAST_DIR = "/" ]; then
LAST_DIR=""
fi
DIFFC=`diff ${LAST_DIR}${CONF} ${DIR}${CONF} | wc -l`
if [ $DIFFC -gt 0 ]; then
echo "[[[ Difference between ${LAST_DIR}${CONF} and ${DIR}${CONF} ]]]"
diff ${LAST_DIR}${CONF} ${DIR}${CONF}
echo ""
fi
DIFFC=0
else
if [ ! -f ${LAST_DIR}${CONF} ]; then
echo "File ${LAST_DIR}${CONF} does not existed."
fi
fi
LAST_DIR=$DIR
done
done
echo ""
date +"%Y/%m/%d %H:%M:%S"
3. 使用範例
/PATH/TO/CHK_ETC_diff.sh /PATH/TO/SRC SNAPSHOT_KEYWORD /PATH/TO/SNAPSHOT_ROOT
No comments:
Post a Comment