本文共 1381 字,大约阅读时间需要 4 分钟。
HOSTNAME=`hostname`INDEX="template"GSMSERVER=emp01.baidu.comGSMPORT=15001EMAIL_LIST="yangmin11@baidu.com"function CAT_EMAIL_LIST() { # 按EMAIL_LIST列表发送邮件 ELIST="" for i in $* do if [ -z $ELIST ]; then ELIST=$i else ELIST=$ELIST,$i fi done echo $ELIST}function check_dir_exist() { last_week=$(date -d '-7 day' '+%Y%m%d') # 获取上周时间 today=$(date "+%Y%m%d") # 获取今天时间 output_path=$(dirname ${ 1}) # 获取目录前缀 ${hadoop_bin} fs -test -e $output_path/$today # 检测hdfs文件是否生成成功 if [ $? -eq 0 ] ;then today_file_count=$(${ hadoop_bin} dfs -count -q $output_path/$today | awk '{ for(i=5;i<=NF;i++) printf $i"\t";printf "\n"}' | cut -f 3) # 统计刚生成的文件量 if [ $today_file_count -eq 0 ] ;then # 如果统计文件大小结果为0,表示没有生成成功 ELIST="$(CAT_EMAIL_LIST $EMAIL_LIST)" # 发邮件 echo "$output_path/$today generation fail" | mail -s "$1" "$ELIST" return 1 else # 如果统计结果大于0,表示今天生成成功,可以删除上周备份 ${hadoop_bin} fs -test -e $output_path/$last_week if [ $? -eq 0 ] ;then ${hadoop_bin} fs -rmr $output_path/$last_week else # 如果上周目录不存在,可能有其他变动,发邮件 ELIST="$(CAT_EMAIL_LIST $EMAIL_LIST)" echo "$output_path/$last_week is not exist" | mail -s "$1" "$ELIST" fi fi else return 0 fi}
转载地址:http://dumfb.baihongyu.com/