temp脚本
!/bin/bash
source ${HOME_DIR}/script/ideploy_dm.inc
source ${HOME_DIR}/script/comm_lib
home_dir=$(cd dirname $0
; pwd)
脚本执行的输出日志
logFile="./cmi_data_process.log"
输入文件-当前目录下的
inputFileName="cmi_data_process_inputfile.txt"
输出文件-当前目录下的
outputFileName="cmi_data_process_outputfile.txt"
output_file="$home_dir/../output/output_file"
输出日志
function echoLog()
{
echo data
":"$1 >>$logFile
}
function download_from_service
{
local des_path=$1
local local_path=$2
echo " ***********************check_read_permission ${usr_name} ${server_ip} ${usr_pwd} ${service_dir}/${des_path}"
check_read_permission ${usr_name} ${server_ip} ${usr_pwd} ${service_dir}/${des_path}
if [ $? -ne 0 ];then
log_echo "err" "download_from_service" "${usr_name} can not read ${service_dir}/${des_path} on ${server_ip}."
return 1
fi
local des_file=${des_path##*/}
if [ -e ${local_path}/${des_file} ];then
rm ${local_path}/${des_file}
fi
scp_file_from_remot_to_local ${service_dir}/${des_path} ${local_path} ${server_ip} ${usr_name} ${usr_pwd}
if [ $? -ne 0 ];then
log_echo "err" "download_from_service" "scp ${service_dir}/${des_path} from ${server_ip} by ${usr_name} ${FAILED}."
return 1
fi
return 0
}
function get_service_info
{
server_ip=$(grep "service_ip" ${CONF_FILE} |grep -oP '(?<).*')
usr_name=$(grep "sshusr_name" ${CONF_FILE} |grep -oP '(?<).')
service_dir=$(grep "service_dir" ${CONF_FILE} |grep -oP '(?<==).')
local usr_aes_pwd=$(grep "sshusr_pwd" ${CONF_FILE} |grep -oP '(?<).*')
if [ "$usr_name" == "" ];then
usr_name="root"
usr_aes_pwd=$(grep "root_pwd" ${CONF_FILE} |grep -oP '(?<).*')
fi
standard_decrypt "${usr_aes_pwd}" || return 1
usr_pwd=${RETURN[0]}
local_config_path=${cur_dir}/cutover_file
if [ ! -e $local_config_path ];then
mkdir -p $local_config_path
fi
}
function process_hms_for_cmi
{
cd /tmp/device_collect
resultFile=$home_dir"/"$inputFileName
if [ ! -f $resultFile ];then
touch $resultFile
fi
ls -l | grep -v total | grep -v device|awk -F" " '{print $9}' >$resultFile
sed -i 's/_/ /g' $resultFile
sed -i 's/#/ /g' $resultFile
cp $resultFile $home_dir
cd $home_dir
}
main()
{
echo "before get_service_info."
get_service_info
echo "after get_service_info."
download_from_service device_collect/ /tmp
echo "after download."
process_hms_for_cmi
echo "after process_hms_for_cmi."
#获取数据库 连接串/用户名/密码
JDBCURL=`grep 'jdbc.url=' /home/huawei/mdn2000/cmi/WebRoot/WEB-INF/conf/jdbc.properties | awk -F '=' '{print $2}'`
DBUSERNAME="iptvmdn"
local usr_aes_pwd=$(grep "DATABASE_PASS" ${CONF_FILE} |grep -oP '(?<==).*')
standard_decrypt "${usr_aes_pwd}" || return 1
DBPASSWORD=${RETURN[0]}
#查询哪些文件是需要修改的,中间文件nvodXmlFiles.txt,最终要修改的文件 toBeProcessedFiles.txt
oldIpStrs=`cat cmi_data_process_inputfile.txt | awk -F ' ' -v var='' '{ for(j=2;j<=NF;j++) var=var$j"|"} END { print var}'`
echo $oldIpStrs
oldIpStrs=${oldIpStrs%|*}
echo $oldIpStrs
grep -r 'type="nvod"' /home/huawei/mdn2000/cmi/WebRoot/wsx/* | awk -F ':' '{print $1}' > nvodXmlFiles.txt
rm -rf toBeProcessedFiles.txt
for line in $(cat nvodXmlFiles.txt)
do
count=`grep -E $oldIpStrs -c $line`
echo "count:"$count
#count=`grep -E "192.168.1.1|10.0.194.16" -c $line`
if (($count>0))
then
echo $line >> toBeProcessedFiles.txt
fi
done
sum=`cat toBeProcessedFiles.txt|wc -l`
echo "sum:" $sum
#是否有文件需要处理
if [ $sum -eq 0 ];then
echo "No file need to process,finished"
exit 0;
fi
chown cmi:mdn2000 toBeProcessedFiles.txt
#创建输出结果文件
if [ -e $outputFileName ];then
rf -rf $outputFileName
fi
touch $outputFileName
#创建已被修改的文件列表--记录修改了哪些文件
modifiedNvodFileList=modifiedNvodFileList.txt
if [ -e $modifiedNvodFileList ];then
rm -rf $modifiedNvodFileList
fi
touch $modifiedNvodFileList
#备份整个wsx目录,以防万一,不存在则创建, 如果存在,则将原来的备份用时间重命名
xmlFolderbak="/home/huawei/mdn2000/cmi/WebRoot/wsx-bak"
if [ -e $xmlFolderbak ];then
bakDirCreateTime=`stat $xmlFolderbak | grep Modify| awk '{print$2$3}'`
echo "bakDirCreateTime:"$bakDirCreateTime
bakDirName=$xmlFolderbak"-"$bakDirCreateTime
mv $xmlFolderbak $bakDirName
fi
cp -rp /home/huawei/mdn2000/cmi/WebRoot/wsx /home/huawei/mdn2000/cmi/WebRoot/wsx-bak
#将待处理的文件列表页备份上,回滚时按此文件进行回退
cp -p toBeProcessedFiles.txt /home/huawei/mdn2000/cmi/WebRoot/wsx-bak/toBeProcessedFiles.txt
#调用jar包处理
java -jar NvodFileUpgrade.jar cmi_data_process_inputfile.txt $JDBCURL $DBUSERNAME $DBPASSWORD /home/huawei/mdn2000/cmi/WebRoot/wsx/ NvodFileUpgradeBak cmi_data_process_outputfile.txt toBeProcessedFiles.txt
resultCode=$?
echo "java -jar resultCode:"$resultCode
if [ $resultCode -ne 0 ];then
exit $resultCode;
fi
echo $home_dir"/"$outputFileName > $output_file
return 0
}
main