最近上班无事,想起以前模块修改完成,工程中改变了的文件要按照目录提取出来,然后打成包发给老大。之前我一直是自己手动建目录,复制文件,这样太低效率了,我就做了shell脚本来完成这个:
#!/bin/bash
if [ $# -ne 2 ]
then
echo "usage: $0 path_diff path_base"
exit -1
fi
DIFF_PATH=${1%%\/}
BASE_PATH=${2%%\/}
EXTRACT_PATH=$PWD"/""package"
if !( [ -d $INIT_PATH ] && [ -d $BASE_PATH ] )
then
echo "$INIT_PATH or $BASE_PATH not exist"
exit -1
fi
if [ -d $EXTRACT_PATH ]
then
echo "path $EXTRACT_PATH exist, delele it"
rm -r $EXTRACT_PATH
fi
rm -f file.list diff.list
function ergodic(){
for file in ` ls $1 `
do
if [ -d $1"/"$file ]
then
cur_path=$2"/"$file
ergodic $1"/"$file $cur_path
else
echo $1"/"$file >> file.list
#echo $2
diff $1"/"$file $BASE_PATH$2"/"$file > temp.diff
if [ -s temp.diff ]
then
if ! [ -d $EXTRACT_PATH$2 ]
then
mkdir -p $EXTRACT_PATH$2
fi
cp -f $1"/"$file $EXTRACT_PATH$2"/"$file
echo $1"/"$file >> diff.list
fi
rm -rf temp.diff
fi
done
}
ergodic $DIFF_PATH ""
if [ -s diff.list ]
then
echo "extract success"
fi
该脚本是根据一个遍历目录下文件的脚本改的,这个脚本是对比两个目录,所以需要有一个base project. 另外还有个cvs版本的:
#!/bin/bash
if [ $# -ne 1 ]
then
echo "usage: $0 path_diff"
exit -1
fi
DIFF_PATH=${1%%\/}
EXTRACT_PATH=$PWD"/""package"
if !( [ -d $INIT_PATH ] )
then
echo "$INIT_PATH not exist"
exit -1
fi
if [ -d $EXTRACT_PATH ]
then
echo "path $EXTRACT_PATH exist, delete it"
rm -r $EXTRACT_PATH
fi
rm -f file.list diff.list
function ergodic(){
for file in ` ls $1 `
do
if [ -d $1"/"$file ]
then
if [ $file != "CVS" ]
then
cur_path=$2"/"$file
ergodic $1"/"$file $cur_path
fi
else
echo $1"/"$file >> file.list
#echo $2
cvs diff $1"/"$file > temp.diff
if [ -s temp.diff ]
then
if ! [ -d $EXTRACT_PATH$2 ]
then
mkdir -p $EXTRACT_PATH$2
fi
cp -f $1"/"$file $EXTRACT_PATH$2"/"$file
echo $1"/"$file >> diff.list
fi
rm -rf temp.diff
fi
done
}
ergodic $DIFF_PATH ""
if [ -s diff.list ]
then
echo "extract success"
fi
如果大家感兴趣的话,可以看一看。