#!/bin/ksh
# $Header: $
# $Modtime:$
################################################################################
# COPYRIGHT. HANG SENG BANK LIMITED 2013. ALL RIGHTS RESERVED.
# NO PART OF THIS PUBLICATION MAY BE REPRODUCED, STORED IN A RETRIEVAL SYSTEM,
# OR TRANSMITTED, ON ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,
# PHOTOCOPYING, RECORDING, OR OTHERWISE, WITHOUT THE PRIOR WRITTEN PERMISSION
# OF HANG SENG BANK LIMITED.
#
# Filename : projectx_rename (shell script file)
#
# Author : Luffy Cao
#
# Abstract : Check the Trade reports delivery signal of Bank level
#
# Modification History :
#
# Version Date Author Description
#------------- -------------- --------------- ------------------------------
# 1.0 26 Jun 2013 Luffy Cao Initial Creation
#
##############################################################################
rootpath=$0
cd "${rootpath%/*}"
file=`echo $0 | cut -d'/' -f5`
# The report file (pdf, html, etc) to be renamed
param_src_file=$1
# The corresponding XML file containing information for renaming
param_xml_file=$2
#set up path
log_path=`awk NR==2 ../JobSch.ini | cut -f1`
raw_path=`awk NR==3 ../JobSch.ini | cut -f1`
report_path=`awk NR==17 ../JobSch.ini | cut -f1`
#set up log file and date file
log_file_1=$log_path/${file}_1.log
log_file_2=$log_path/${file}_2.log
date_file=$report_path/projectx_date.txt
echo "Start to execute "$file" ..."
#Create log file
createLogfile()
{
echo "" > $1
}
#xpath function for XML parsing
xpath()
{
echo "cat $1" | xmllint --shell $2 | sed '/^\/ >/d'
}
#Get content of tag from XML file
getContent()
{
xmlcode=$1
checktag=$2
content=`xpath "//*[local-name()='outputDescriptor']/*[local-name()='$checktag']/text()" $xmlcode`
echo $content
}
#Get value from content of tag in XML file
getValue()
{
xmlcontent=$1
checkstr=$2
found=1
count=2
value=""
while [ $found -ne 0 ]
do
valuetmp=`echo "$xmlcontent" |awk -F \/ '{ print $'$count' }' | sed -r "s/(\[|\]|')//g"`
if [[ $valuetmp == $checkstr* ]]
then
value=$valuetmp
found=0
else if [ -z "$valuetmp" ]
then break
fi
fi
count=$(( $count + 1 ))
done
echo $value
}
#Get name
getName()
{
bfrenm=$1
afrenm=`echo "$bfrenm" |awk -F = '{ print $2 }'`
echo $afrenm
}
#Compare strings
checkStr()
{
str1=$1
str2=$2
if [ "$str1" = "$str2" ]
then
return 0
else
return 1
fi
}
# check xml package name
isPackage()
{
xmlsource=$1
pkgname=$2
strContent=$(getContent $xmlsource reportSearchPath)
szpkg=$(getValue "$strContent" "package")
finalpkgnm=$(getName "$szpkg" )
#Compare
checkStr "$pkgname" "$finalpkgnm"
checkStrcode=`echo $?`
return $checkStrcode
}
#Rename pdf file
getNewName()
{
xmlsource=$1
nName="Unknown Report (PROJECTX)"
strContent=$(getContent $xmlsource reportViewSearchPath)
#validRpt=$(getValue "$strContent" "folder")
#vaildRpt2=$(getName "$validRpt")
nametmp=$(getValue "$strContent" "reportView")
#if [ "$vaildRpt2" = "Generated Reports" ]
#then
if [ -z "$nametmp" ]
then
echo "reportView not found."
else
nName=$(getName "$nametmp")
fi
#fi
echo $nName
}
#copy file and put it to /REPORT
moveFile()
{
oldpdf=$1
newpdf=$2
ext=$3
if [[ "$oldpdf" == *\.$ext ]]
then mv $raw_path/$oldpdf $report_path/$newpdf
fi
}
#create dummy control files
CreateControlFile()
{
ctlname=$1".ctl"
content=$2
echo $content > $report_path/$ctlname
#change group permissions
[ -f $report_path/$ctlname ] && { chgFileGroupAccess $report_path/$ctlname; }
}
# Change File Group Access
chgFileGroupAccess ()
{
outfilename=$1
chgrp cogmap_jbsrun $outfilename
chmod g+rw $outfilename
}
#Create execution control file
CreateEXEControlFile()
{
ctlexename=$1".txt"
content1=$2
content2=$3
echo $content1 > $report_path/$ctlexename
echo $content2 >> $report_path/$ctlexename
}
#Get verDate
getVerDate()
{
xmlsource=$1
verdte="Unknown Date"
verdte=`xpath "//*[local-name()='outputDescriptor']/*[local-name()='parameterValues']/*[local-name()='item']/*[local-name()='name'][text()='Ver Date']/../*[local-name()='value']/*[local-name()='item']/*[local-name()='display']/text()" $xmlsource`
echo $verdte
}
#write verdate txt file
writeDateFile()
{
verdte=$1
echo $verdte > $date_file
}
#housekeeping remove xml after renaming
removeXML()
{
xmlfile=$1
rm -f $xmlfile
}
#Get log file name
getLogFileName()
{
reminder=`echo "\`date +%m\`%2" | bc`
if [ $reminder -ne 0 ]
then
echo "1"
else
echo "2"
fi
}
#Reset log file if now month
tryResetLog()
{
resetLog=1
logfile=$1
logNum=$2
if [ -f $logfile ]
then
modMonth=`echo \`ls -l $logfile\` | awk '{print $6}'`
nowMonth=`echo \`date +%b\``
if [ "$modMonth" = "$nowMonth" ]
then
resetLog=0
fi
else
resetLog=0
createLogfile $1
fi
if [ $resetLog -eq 1 ]
then
rm -f $logfile
createLogfile $1
fi
}
getExtension()
{
source=$1
getext=`echo "$source" |awk -F \. '{ print $2 }'`
[ "$getext" = "mht" ] && { getext="xls" ;}
echo $getext
}
getDataRdyStus()
{
xmlsource=$1
getDataRdyStus="Unknown Status"
getDataRdyStus=`xpath "//*[local-name()='outputDescriptor']/*[local-name()='parameterValues']/*[local-name()='item']/*[local-name()='name'][text()='Data Ready Status']" $xmlsource`
[ -z $getDataRdyStus ] && { status="N"; } || { status="Y" ;}
echo $status
}
# for f in `ls $raw_path/*.xml`
# do
starttime=`date`
xmlfilename=`basename $param_xml_file`
LogFileNum=$(getLogFileName)
if [ $LogFileNum = 1 ]
then
tryResetLog $log_file_1 $LogFileNum
LogFileName=$log_file_1
else
tryResetLog $log_file_2 $LogFileNum
LogFileName=$log_file_2
fi
if [ ! -f $param_xml_file ]; then
echo "$param_xml_file not exists." | tee -a $LogFileName
exit 1
fi
pdffilepath=$(getContent $param_xml_file fileName)
echo "************************************" | tee -a $LogFileName
echo "Date: "$starttime | tee -a $LogFileName
echo "Parsing XML: "$xmlfilename | tee -a $LogFileName
echo "Original PDF: "$pdffilepath | tee -a $LogFileName
# xml reture error code
xmlretcode=`echo $?`
if [ $xmlretcode -ne 0 ]
then
echo "Fail to parse xml file "$xmlfilename | tee -a $LogFileName
exit $xmlretcode
else
echo "Start Parse XML file "$xmlfilename | tee -a $LogFileName
isPackageretcode=1
isPackage $param_xml_file "ProjectX"
isPackageretcode=`echo $?`
echo "isPackageretcode:$isPackageretcode --new added " | tee -a $LogFileName
if [ $isPackageretcode -eq 0 ]
then
echo "File belongs to PROJECTX" | tee -a $LogFileName
newName=$(getNewName $param_xml_file)
if [[ $newName == *"Unknown Report (PROJECTX)"* ]]
then
echo "$newName, File skipped." | tee -a $LogFileName
else
fileext=$(getExtension $pdffilepath)
fullnewName=$newName"."$fileext
echo "Parsed New File Name: "$fullnewName | tee -a $LogFileName
rptVerDte=$(getVerDate $param_xml_file)
echo "Report Version Date: "$rptVerDte | tee -a $LogFileName
#if [[ -z $rptVerDte || "$rptVerDte" = "Unknown Date" ]]
#then
#echo "Invalid Date String: [" $rptVerDte "]" | tee -a $LogFileName
#else
echo "Output Date String: [" $rptVerDte "]" | tee -a $LogFileName
#moveFile $pdffilepath $fullnewName $fileext
#if [[ "$pdffilepath" == *\.$fileext ]]; then
mv $raw_path/$pdffilepath $report_path/$fullnewName
echo "Copy XML File to report parth." | tee -a $LogFileName
ret1=`echo $?`
if [ $ret1 -ne 0 ]; then
echo "Failed to move $raw_path/$pdffilepath $report_path/$fullnewName" | tee -a $LogFileName
exit 1
fi
#fi
# change group
[ -f $report_path/$fullnewName ] && { chgFileGroupAccess $report_path/$fullnewName; }
# Create dummy control file
CreateControlFile $newName ""
# Create execution control file for LN
#CreateEXEControlFile $newName "Y" $rptVerDte
#writeDateFile $rptVerDte
removeXML $param_xml_file
#fi
fi
else
echo "File does not belong to PROJECTX" | tee -a $LogFileName
fi
fi
#done
# reture error code
# retcode=`echo $?`
# if [ $retcode -ne 0 ]
# then
# echo "Fail to execute "$file | tee -a $LogFileName
# exit $retcode
# fi
echo "Successful execution of "$file
exit 0
相关推荐
it is good for KETAB and many other people
rename base dir name `project-tornado` to you `project_name`.1. find all "project_tornado" replace to `you project_name`2. rename folders "project_tornado" to you `project_name`3. find all ...
显示的工程名还是newProject,后我尝试修改其他工程的工程名,发现都不会出现这种情况,所以我断定应该在Refactor->Rename时出现了问题。 之后我用EditPlus打开D:\MyWork\newProject\.settings\org.eclipse.wst....
重命名VC工程的小工具,有时候以前写的VC程序需要重命名一下,使用这个工具可以很方便的修改VC工程里的各个文件为新名称。 程序支持从资源管理器直接拖放VC工程文件到程序窗口。
在Tomcat6下使用Log4j记录日志,...网上查找了下原因,大概意思是日志文件始终被占有,所以当log4j对日志文件进行rename时,就发生了Failed to rename错误 。要修改log4j的源码,附件是我修改好后的,方便大家下载使用
在国外网站上找到的一个VS工程重命名的工具,挺好用的,软件需要安装后使用。
12/ rename parameter Name to AName in define event TExecOpenDialogEvent, because occur names conflict. 13/ repair conflict in string property in module RxTranslate for unicodes. 14/ some functions ...
# Rename example .env mv .env.example .env # Enter your own environment variables cat << EOF>.env export GCP_PROJECT_NUMBER= export GCP_PROJECT_ID= export GCP_WORKLOAD_ID= export GC
12/ rename parameter Name to AName in define event TExecOpenDialogEvent, because occur names conflict. 13/ repair conflict in string property in module RxTranslate for unicodes. 14/ some functions ...
12/ rename parameter Name to AName in define event TExecOpenDialogEvent, because occur names conflict. 13/ repair conflict in string property in module RxTranslate for unicodes. 14/ some functions ...
Before build project rename file build.properties.pattern in build.properties and set specific for your machine parameters, then start build.bat (for Windows platform) or build.sh (for Linux)...
Gulp 入门模板用于开发的 Gulp.js 入门模板。特征JavaScript 使用 uglify 压缩。 将 SCSS 文件编译为 CSS。 缩小和复制 CSS 文件。 当文件更改时,使用浏览器同步自动重新加载所有浏览器。...minify-css gulp-rename gu
// or project specific include files that are used frequently, but // are changed infrequently // #if !defined(AFX_STDAFX_H__58C73787_1231_40B3_A8BC_2F7670ABA3D7__INCLUDED_) #define AFX_STDAFX_H__58C...
cse210项目为了女王您必须雇用快乐的人来保护我们的女王免受怪物的袭击规划清醒图表入门[如何安装和运行程序]项目结构项目文件和文件夹的组织方式如下: root (project root folder)+-- docs (project documentation...
使用Gradle的Java gRPC Hello World 这段代码几乎是gRPC的java hello world示例,但是在一个单独的存储库中,并且...它也依赖于gnu-sed,因此,如果您的脚本不在PATH变量中,则可以手动设置它: SED=gsed ./rename_pac
问题描述: 在使用git 进行提交时, 出现上面这个报错, 导致...///Users/dianji/project/ccpay.h5/.git/index.lock是你的index.lock的目录, 通常直接复制报错信息里边的地址比较靠谱. 那这个index.lock有什么作用呢? 官
ember-cli-rename ember-cli的蓝图重命名命令。 目前在制品,使用后果自负! 用法 要安装ember-cli-rename ,请在... Moves files in an ember-cli project and updates path references. aliases: re --dry-run (B
Before build project rename file build.properties.pattern in build.properties and set specific for your machine parameters, then start build.bat (for Windows platform) or build.sh (for Linux) in root...
6) Rename the pins and connect them to the appropriate ports on the symbol. 7) Save the BDF as a unique filename. 8) Set the BDF as your top level entity by clicking: Project -> Set as Top-Level ...
CSCI3100项目这是在线二手书销售... This is a recommended format for branch namesbuild/changes-on-the-deploymentdocs/write-some-documentationfeat/add-a-new-featurefix/fix-a-bugrefactor/rename-a-file-or-fo