1.shell 脚本实现检测目标文件是否生成,若未生成,则等待10min,再次检测
#!/bin/bash # /** # * @file "test.sh" # * @brief "循环检测文件生成调用脚本" # * @Created on "2020-09-01" # * @author "zz" # **/ done_file="/data/zz/done.txt" last_dt=`date -d "1 day ago $current_dt" +%Y-%m-%d` echo ${last_dt} while : do model_score_output_dt=`cat $done_file` echo ${model_score_output_dt} if [ "$model_score_output_dt" = "$last_dt" ];then echo "$done_file ---> ready!" break 2 # 跳出循环 fi echo "waiting 10min ..." #sleep `expr 60 \* 10` # 注意shell中的乘法! sleep 600s done echo "job starting..."或
done_file="done.txt" last_dt=`date -d "1 day ago $current_dt" +%Y-%m-%d` echo ${last_dt} model_score_output_dt=$(cat $done_file) until [ "$model_score_output_dt" == "$last_dt" ] do echo "waiting 10min ..." sleep 600s model_score_output_dt=$(cat $done_file) echo ${model_score_output_dt} done echo "$done_file ---> ready!" echo "job starting..."2. 任务执行成功则退出,不成功则尝试执行3次
iRetryTimes=0 while ((iRetryTimes < 3)) do let ++iRetryTimes bash run_job.sh \ ${param1} \ ${param2} \ >> run_job.$(date '+%Y-%m-%d.%H.%M').log 2>&1 if [ $? -eq 0 ]; then break fi done echo "--done!"
