输入文件是CASH_FORECAST_STATUS.TXT并包含以下内容
$ cat CASH_FORECAST_STATUS.TXT
TEST-CASH-FCST-1-|CASHFC|EFT Format via FG|382
TEST-CASH-FCST-2-|CASHFC|EFT Format via FG|654
TEST-CASH-FCST-3-|CASHFC|EFT Format via FG|234
TEST-CASH-FCST-4-|CASHFC|EFT Format via FG|123
TEST-CASH-FCST-5-|CASHFC|EFT Format via FG|789
TEST-CASH-FCST-6-|CASHFC|EFT Format via FG|334
TEST-CASH-FCST-7-|CASHFC|EFT Format via FG|125
我被要求更改以下脚本,以便它能够一次处理状态文件中的5行,并且当一个作业成功完成时,将另一个作业添加到列表中。这个想法在Autosys中一次只能运行5个工作。
#!/bin/sh
MYSTATUSFILE=$1; export MYSTATUSFILE
MYWRKDIR=$AUTOUSER/output; export MYWRKDIR
MYWRKTYPE=`echo $MYSTATUSFILE | cut -d\_ -f2`; export MYWRKTYPE
MYPSMACHINE=FSM; export MYPSMACHINE;
MYPID=$$
#echo $MYPID
echo $MYWRKTYPE
TODAYS_DATE_TIME=`date +%Y%m%d.%H%M`; export TODAYS_DATE_TIME
cp $MYWRKDIR/$MYSTATUSFILE $MYWRKDIR/$MYSTATUSFILE.$TODAYS_DATE_TIME
cp $MYWRKDIR/$MYSTATUSFILE $MYWRKDIR/$MYSTATUSFILE.TRIM
cat $MYWRKDIR/$MYSTATUSFILE | cut -d\| -f1-2 >$MYWRKDIR/$MYWRKTYPE_WORK.$MYPID
for LINE in `cat $MYWRKDIR/$MYWRKTYPE_WORK.$MYPID`; do
PROGNAME=`echo $LINE | cut -d\| -f1`
PROGRUNCTL=`echo $LINE | cut -d\| -f2`
echo $PROGNAME
echo $PROGRUNCTL
# Turns out some jobs have no dash at the end but rest of the PROGNAMEs do. SO we adjust the name for setting the job name
case $PROGNAME in
CHKX00)
PROGNAMEEXT="$PROGNAME"-
PROGNAMEVAR="$PROGNAME"-GVAR
;;
CHKX0S)
PROGNAMEEXT="$PROGNAME"-
PROGNAMEVAR="$PROGNAME"-GVAR
;;
*)
PROGNAMEEXT="$PROGNAME"
PROGNAMEVAR="$PROGNAME"GVAR
;;
esac
echo $PROGNAME $PROGNAMEEXT $PROGNAMEVAR
sendevent -E SET_GLOBAL -G"$PROGNAMEVAR=$PROGRUNCTL"
sleep 10
sendevent -E FORCE_STARTJOB -J CM_CF-"$PROGNAMEEXT""$MYWRKTYPE"_"$MYPSMACHINE"_B
# Now check for success status of this job
sleep 20
CHK_STATUS=`autostatus -J CM_CF-"$PROGNAMEEXT""$MYWRKTYPE"_"$MYPSMACHINE"_B`
echo $CHK_STATUS
#Loop until CHK_STATUS is SUCCESS or FAILURE or TERMINATED
until [ "$CHK_STATUS" = "SUCCESS" ]
do
case $CHK_STATUS in
INACTIVE)
sleep 20
CHK_STATUS=`autostatus -j CM_CF-"$PROGNAMEEXT""$MYWRKTYPE"_"$MYPSMACHINE"_B`
;;
ACTIVATED)
sleep 20
CHK_STATUS=`autostatus -j CM_CF-"$PROGNAMEEXT""$MYWRKTYPE"_"$MYPSMACHINE"_B`
;;
INITIATED)
sleep 20
CHK_STATUS=`autostatus -j CM_CF-"$PROGNAMEEXT""$MYWRKTYPE"_"$MYPSMACHINE"_B`
;;
STARTING)
sleep 20
CHK_STATUS=`autostatus -j CM_CF-"$PROGNAMEEXT""$MYWRKTYPE"_"$MYPSMACHINE"_B`
;;
RUNNING)
sleep 20
CHK_STATUS=`autostatus -j CM_CF-"$PROGNAMEEXT""$MYWRKTYPE"_"$MYPSMACHINE"_B`
;;
FAILURE)
echo $PROGNAME has a FAILURE status
exit 1
;;
TERMINATED)
echo $PROGNAME has a TERMINATED status
exit 2
;;
esac
done
# Reached here because of SUCCESS or FAILURE or TERMINATED only
case $CHK_STATUS in
FAILURE)
echo $PROGNAME has a FAILURE status
exit 1
;;
TERMINATED)
echo $PROGNAME has a TERMINATED status
exit 2
;;
SUCCESS)
sed /$LINE/d $MYWRKDIR/$MYSTATUSFILE >/$MYWRKDIR/$MYSTATUSFILE.TRIM
diff $MYWRKDIR/$MYSTATUSFILE.TRIM $MYWRKDIR/$MYSTATUSFILE
mv $MYWRKDIR/$MYSTATUSFILE.TRIM $MYWRKDIR/$MYSTATUSFILE
;;
esac
done
此脚本当前将在Autosys中启动1个作业,并等待成功继续输入文件CASH_FORECAST_STATUS.TXT
中的下一行最终它将同时启动以下作业:CM_CF-TEST-CASH-FCST-1-FORECAST_FSM_B通过CM_CF-TEST-CASH-FCST-5-FORECAST_FSM_B。当其中一个完成时,它应该启动CM_CF-TEST-CASH-FCST-6-FORECAST_FSM_B并监视是否成功。
我不确定是否需要创建另一个文件来传递作业名称以进行监视并为文件提供限制,或者我是否可以使用计数器。就脚本而言,这个请求远远超出了我的想法。
我可以回答问题,但我很难让人们理解这一点。