linux批量修改文件属性值

 

#!/bin/sh
old=$1
new=$2
base_root=/usr/local/snsconnector
sns_num=5

for ((i=1;i<${sns_num};i++))
do  
if ((i==1))
then
sed -i "s/${old}/${new}/g" ${base_root}/sns_connector/WebRoot/WEB-INF/classes/test.properties 
sleep 1
echo "the sns_connector1 app test.properties change successful !"
else
sed -i "s/${old}/${new}/g" ${base_root}/sns_connector$i/WebRoot/WEB-INF/classes/test.properties 
sleep 1
echo "the sns_connector$i app test.properties change successful !"
fi
done
echo "all sns_connector change successful!"

 

    保存为chonf.sh 

    执行  chonf.sh appid=1 appid=2   //将appid值由1变为2.

 

 

   批量替换文件脚本 changfile.sh

 

   ./changefile.sh  conf.properties  conf.properties  WebRoot/WEB-INF/classes

 

 

#!/bin/sh
oldFile=$1
newFile=$2
path=$3
base_root=/usr/local/snsconnector
DATE=$(date +"%Y%m%d")
sns_num=5

for ((i=1;i<${sns_num};i++))
do  
if ((i==1))
then
mv ${base_root}/sns_connector/${path}/${oldFile} ${base_root}/sns_upload/${oldFile}_${DATE}
cp -r ${base_root}/sns_upload/${newFile}  ${base_root}/sns_connector/${path}/${newFile}
sleep 2
echo "the sns_connector1 app file change successful !"
else
cp -r ${base_root}/sns_upload/${newFile}  ${base_root}/sns_connector$i/${path}/${newFile}
sleep 2
echo "the sns_connector$i app file change successful !"
fi
done
echo "all sns_connector change successful!"

 

 

 

 

 

你可能感兴趣的:(linux)