直接上干货:
#!/bin/bash -eu
#exec101
set -o pipefail
set +x
source /etc/di-env.sh
source /ubuntu/etl/bin/env.sh
CURDIR=/home/azkaban/test/
cd ${CURDIR}
time1=$(date "+%Y%m%d")
path="/user/azkaban/test/personal/*/210202020${time1}*.txt"
times=1
result=0
while [ true ]
do
echo "尝试运行第"$times"次"
set +e
hadoop fs -test -e ${path}
if [[ $? == 0 ]];then
result=`hdfs dfs -ls ${path}|wc -l`
if [[ result -lt 2 ]];then
echo "文件个数不够,两分钟后再重试"
sleep 2m
else
result=`hdfs dfs -get ${path}`
zip -rP ${time1} ${time1}.gz ${CURDIR}/210202020${time1}*.txt
echo "附件为XXXXXX,请查收" | mail -s "XXXXXX报文" -a ${CURDIR}/${time1}.gz cai.yuan@xxxxxxx.com
if [[ $? == 0 ]];then
echo "邮件发送成功"
exit 0;
else
echo "邮件发送失败,请联系管理员"
exit -1;
fi
fi
elif [[ $times -ge 90 ]]; then
echo "重试次数达90次,任务被杀掉,请联系管理员"
exit -1;
else
echo "文件不存在,两分钟后再重试"
sleep 2m
fi
times=$((${times} + 1))
done