不懂这个脚本,每解析一行得2分.

yeah920 yeah920 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
不懂这个脚本,每解析一行得2分. 除了注释,空白行和输出行.

#!/bin/bash
#
# The following shell variables have to be defined and exported before this shell script is called.
# Example values are show below the variable name
#
# EnvSH
# '/cib/uxprod/java/bin/env.sh'
# ScriptName
# 'loadTxnHistory.sh'
# OnException
# 'doMail_oper "CIB0123E %Y%m%d %T ($ScriptName:exception)"'
# OnComplete
# 'doMail "CIB0113I %Y%m%d %T ($ScriptName:completed)"'
# OnCompleteAfterDelay
# 'doMail "CIB0113I %Y%m%d %T ($ScriptName:completed after delay)"'
# OnMissingFile
# 'doMail "CIB0112E %Y%m%d %T ($ScriptName:file missing)"'
# OnFileDelay
# 'doMail "CIB0111I %Y%m%d %T ($ScriptName:file not ready yet)"'
# MaxWaitMinutes
# 240
# AlertMinutes
# 60
# OneMinute
# 60
# LogFilePath
# '/project/CIB/log/loadTxnHistory.%Y%m%d%H%M%S.log'
# InputDir
# '/project/CIB/ftp/rcv/'
# BackupDir
# '/project/CIB/ftp/backup/rcv/'
# BackupExtension
# '.%Y%m%d%H%M%S'
# WaitFileSet
# 'DLDHY[0-9][0-9].EOF'
# InputFileSetReplace
# 's/DLDHY\(..\)\.EOF/KKKHY\1.TXT:LLLHY\1.TXT/'
# WaitFileSet2
# 'ABC2XYZ.RRR.D[0-9][0-9][0-9][0-9][0-9][0-9].EOF'
# InputFileSet2Replace
# 's/ABC2XYZ/UVW2XYZ/; s/.EOF/.TXT/'
# doImportCallback() { ... }
# a shell function to be exported from the caller shell script
#
# To call this script, type the following statements
#
# export ScriptName OnException OnComplete OnCompleteAfterDelay ...
# export -f doImportCallback
# ./GenericImport.sh
#


is_defined() {
eval val="\${$1}"
if [ "$val" = "" ]; then return 1; else return 0; fi
}
is_defined EnvSH && . $EnvSH
is_defined OneMinute || OneMinute=60
MailContent="$cronjob_subject_prefix Refer to CCB Manual for the Recovery Procedure"
EOFFilelist=""
InputSetList=""
DelayFlag=""

doMail() {
echo $MailContent | mailx -s "$*" $cronjob_maillist
}
doMail_oper() {
echo $MailContent | mailx -s "$*" $cronjob_maillist $oper_maillist
}
doMail_attach() {
file=$1 ; shift
if [ -r "$file" ]; then
cmd="echo $MailContent; uuencode $file `basename $file`"
else
cmd="echo $MailContent; echo $file not found"
fi
eval "$cmd" | mailx -s "$*" $cronjob_maillist
}
doBackup() {
file="$1"
#[ -r "$file" ] && mv $InputDir/$file $BackupDir/$file$BackupExt
}
handle_when_defined() {
eval command="\${$1}"
if [ "$command" = "" ]; then
return 1
else
eval `date +"$command"`
fi
}
wait_for_files() {
elapsed_time=0
while :
do
# convert to input file list
cd $InputDir
for j in $WaitFileSet; do
if test -r "$j" ; then
t=`echo "$j" | sed "$InputFileSetReplace"`
InputSetList="$InputSetList $j:$t"
fi
done
for j in $WaitFileSet2; do
if test -r "$j" ; then
t=`echo "$j" | sed "$InputFileSet2Replace"`
InputSetList="$InputSetList $j:$t"
fi
done
is_defined InputSetList && return 0
if [ $elapsed_time -ge $MaxWaitMinutes ] ; then
echo "== OnMissingFile:eof"
handle_when_defined OnMissingFile
return -1;
elif [ $elapsed_time -eq $AlertMinutes ] ; then
echo "== OnFileDelay"
handle_when_defined OnFileDelay
AlertMinutes=`expr $AlertMinutes + $AlertMinutes`
DelayFlag=1
fi
sleep $OneMinute;
elapsed_time=`expr $elapsed_time + 1`
done
}

OrigDirectory=`pwd`
cd $InputDir
LogFilePath=`date +"$LogFilePath"`
BackupExt=`date +"$BackupExtension"`
exec >$LogFilePath 2>&1
echo "$ScriptName starts at "`date`

if wait_for_files; then
for InputSet in $InputSetList; do
EOFFile=""
InputFiles=`echo $InputSet | tr ':' ' '`
InputSetReady=true
ImportCommand="doImportCallback"
echo "InputSet=$InputSet"
echo "InputFiles=$InputFiles"
for f in $InputFiles ; do
[ ! -r "$f" ] && InputSetReady=""
if is_defined EOFFile ; then
ImportCommand="$ImportCommand $f"
else
EOFFile=$f
echo "EOFFile=$EOFFile"
fi
done
if is_defined InputSetReady
then
# run the import command and move files to backup folder
# the doImportCallback() function is run in a subshell to prevent changes within doImportCallback()
# to affect other part of this script
echo "$ImportCommand"
( eval "$ImportCommand" )
for f in $InputFiles ; do
doBackup $f
done
else
echo "== OnMissingFile:input"
handle_when_defined OnMissingFile
fi
done
# check for exception
if grep Exception $LogFilePath > /dev/null; then
echo "== OnException"
handle_when_defined OnException
else
# complete w/o exception
if is_defined DelayFlag ; then
echo "== OnCompleteAfterDelay"
handle_when_defined OnCompleteAfterDelay
else
echo "== OnComplete"
handle_when_defined OnComplete
fi
fi
fi
echo "$ScriptName ends at "`date`

...全文
评论 8
收藏 已收藏
分享
返回顶部
yeah920
Linux/Unix社区 23,224 成员 74,535 内容