(1)遍历所有的zip文件,将有效的zip生成对应的.ok文件
#!/bin/bash
myPath="数据存放地址"
function echo_name(){
for file in `ls $myPath *.zip`
do
unzip -t $file
if [ $? == 0 ];
then
if [ ! -f $file.ok ];
then
create_ok_file $file
fi
fi
done
}
function create_ok_file(){
echo "开始创建文件.ok文件:"$file
touch $file.ok
echo "创建文件.ok文件结束:"$file
}
echo_name $1
(2)遍历所有的zip文件,对有效的zip【.ok文件】及zip文件进行转移
#!/bin/bash
myPath="数据存放地址"
tergetServerPath="目标用户@目标ip:目标路径"
bakPath="备份用户@备份ip:备份路径"
function echo_name(){
#cd $myPath
for file in `ls $myPath app_*.zip`
do
if test -e $myPath$file.ok
then
echo "the file is exit:"$myPath$file.ok
echo "===============开始传输============="
cd $myPath && scp -r $file.ok $tergetServerPath$file.ok
cd $myPath && scp -r $file $tergetServerPath$file
cd $myPath && scp -r $file.ok $bakPath$file.ok
cd $myPath && scp -r $file $bakPath$file
echo "copy文件及.ok文件结束:"$file
echo ""
echo "===============开始删除============="
rm -rf $myPath$file.ok
rm -rf $myPath$file
else
echo "the file is not exit:"$myPath$file.ok
fi
done
}
echo_name $myPath