发送错误报告时脚本不退出函数

发送错误报告时脚本不退出函数

当我启动脚本时,它仍然处于进程状态,而发送邮件后函数出现错误:

#!/bin/bash
LOG_FILE=/data/logs/file.log
DATE="$(date +%Y%m%d --date="1 day ago")"
##### STEPS #####

### STEP 1:

step_1(){
curl --location --request GET "http://url"
sleep 1m

if  grep -q 'completed!' $LOG_FILE | tail -1 ;then
        report_step_1
        step_2
else
        report_error_step_1
        exit 1
fi
}

### STEP 2:

step_2(){
curl --location --request GET "http://url"
sleep 30m
if  grep -q 'Generete Revenue File completed' $LOG_FILE | tail -1 ;then
        report_step_2
        step_3
else
        report_error_step_2
        exit 1
fi
}

### STEP 3:

step_3(){
curl --location --request GET "http:url"
sleep 30m
if  grep -q 'File correctly sent via ftp' $LOG_FILE | tail -3 ;then
        report_step_3
else
        report_error_step_3
        exit 1
fi
}

report_step_1(){
mail -s "OK" "mail" <<< "STEP 1 completato con successo"
}

report_step_2(){
mail -s "OK" "mail" <<< "STEP 2 completato con successo"
}

report_step_3(){
mail -s "OK" "mail" <<< "STEP 3 completato con successo"
}

report_error_step_1(){
mail -s "FAILED" "mail" <<< "Attenzione: STEP 1 fallito"
exit 5
}

report_error_step_2(){
mail -s "FAILED" "mail" <<< "Attenzione: STEP 2 fallito"
exit 5
}

report_error_step_3(){
mail -s "FAILED" "mail" <<< "Attenzione: STEP 3 fallito"
exit 5
}

step_1
exit 0

有人可以看一下并告诉我为什么退出不起作用以及我是否在其他功能中正确配置了所有退出?

相关内容