下面写的是一个关于文件上传的代码shell脚本
该篇文章主要有以下几个方面的考虑:
1.文章主要用于在Linux下代码包批量上传;
2.将被覆盖的代码备份做备份,用于后续做问题查看或者代码的回退(回退需要对应的脚本,暂未编写);
3.当次上传的代码,也做备份,用于做后续问题跟踪;
以下为更新脚本
#!/bin/sh
updatePackages=$(ls -rt /home/weblogic/apps/updatefile | awk '{print $1}')
updatedir="/home/weblogic/apps/updatefile"
webAppsdir="/home/weblogic/apps"
beforeUpdateWarBak="/home/weblogic/apps/updateBeforeWarBak"
dir="/home/weblogic/apps/updatefile"
webapps=("bfmcp" "bfmmarket")
function ergodic(){
lsdir=$(ls "$1" | awk '{print $1}')
for file in $lsdir
do
if [ -d "$1/$file" ]
then
ergodic "$1/$file" "$2"
else
echo "the directory is ___:$1"
if [[ $file =~ "list_source.txt" ]]
then echo "The file not need to update ---:$file"
else
updatedir=$1
echo "Update direcotry is -----------:$updatedir"
bfmdir=${updatedir##*bfmmarketn}
pdir=${updatedir##*updatefile/}
pdirs=${pdir%%bfmmarketn*}
echo "bfm war bak directory is ------:$beforeUpdateWarBak/$pdirs$2$bfmdir"
echo "bfm war directory is ----------:$webAppsdir/$2$bfmdir"
echo "Update file is ----------------:$1/$file"
if [ -e "$beforeUpdateWarBak/$pdirs$2$bfmdir" ]
then echo "bfm war bak directory is exist -------:$beforeUpdateWarBak/$pdirs$2$bfmdir"
else
echo "bfm war bak is not exist,make directory is ----------------:$beforeUpdateWarBak/$pdirs$2$bfmdir"
mkdir -p "$beforeUpdateWarBak/$pdirs$2$bfmdir"
fi
echo "search the war file is or not exist ------: $webAppsdir/$2$bfmdir/$file"
if [ -e "$webAppsdir/$2$bfmdir/$file" ]
then
echo "war file is exist,copy to the file is ---:$beforeUpdateWarBak/$pdirs$2$bfmdir"
cp -rf $webAppsdir/$2$bfmdir/$file $beforeUpdateWarBak/$pdirs$2$bfmdir
else
echo "war file is not exist,don't need to copy the file to war bak---:$webAppsdir/$2$bfmdir/$file"
fi
echo "search the bfm war directory is or not exist ----:$webAppsdir/$2$bfmdir"
if [ -e "$webAppsdir/$2$bfmdir" ]
then echo "bfm war directory is exist,don't need to make the file ------:$webAppsdir/$2$bfmdir"
else
echo "bfm war directory is exist is not exist,need to make the file:$webAppsdir/$2$bfmdir"
mkdir -p "$webAppsdir/$2$bfmdir"
fi
echo "update file to bfm war direcotry ---------:$1/$file to $webAppsdir/$2$bfmdir"
cp -rf $1/$file $webAppsdir/$2$bfmdir
fi
fi
done
}
for updatePackage in $updatePackages
do
echo "$updatePackage"
if [[ $updatePackage =~ "All" ]]
then
echo "Now update package is ----: $updatePackage"
for warName in ${webapps[@]}
do
echo "Now update package is :$updatePackage and the update war name is :$warName"
ergodic "$dir/$updatePackage" $warName
done
else
warName=$(ls $updatedir | awk -F '--' '{print $2}')
if [[ $warName =~ "bfm" ]]
then
ergodic "$dir/$updatePackage" "$warName"
else
echo "$warName"
fi
fi
if [ -e "$webAppsdir/updatePackageBak/$updatePackage" ]
then
echo "updatePackage is exist,need to delete the file ---: $webAppsdir/updatePackageBak "
rm -r "$webAppsdir/updatePackageBak/$updatePackage"
else
echo "no action"
fi
mv "$dir/$updatePackage" "$webAppsdir/updatePackageBak/"
done