source ${HOME_DIR}/script/ideploy_dm.inc
source ${HOME_DIR}/script/comm_libjava
home_dir=$(cd dirname $0
; pwd)數據庫
logFile="./cmi_data_process.log"bash
inputFileName="cmi_data_process_inputfile.txt"ssh
outputFileName="cmi_data_process_outputfile.txt"
output_file="$home_dir/../output/output_file"ide
function echoLog()
{
echo data
":"$1 >>$logFile
}url
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
}code
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 '(?<==).*')
fiserver
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
}xml
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