检查文件是否生成成功
HOSTNAME=`hostname`
INDEX="template"
GSMSERVER=emp01.baidu.com
GSMPORT=15001
# 如果只有一个参数,那么退出
if [ $# -le 1 ];
then
echo "Usage: $0 <python_file_name> <output_path> <input_paths>"
exit 1
fi
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') # 获取当前-7天的时间
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
}
参数变长获取
# 打印所有输入
export LC_ALL="C"
if [ $# -le 1 ];
then
echo "Usage: $0 <output_path> <input_paths>"
exit 1
fi
# 第一个是输出文件,之后全部参数是输入文件
OUTPUT_PATH=$1
input_args=""
for ((i=2;i<=$#;i++));
do
eval a=\${${i}}
input_args=$input_args" -input $a"
done
echo $input_args
for循环之并行-手动多线程
random_query_name="query_random_0315"
thread_num=50
size=`expr 20000 / $thread_num`
split -l $size $random_query_name -d -a 3 random_
mv random_* query_data
python3 gen_list.py $thread_num> list_to_run
env_list=('njjs.wisedebug.baidu-int.com' 'hbe.wisedebug.baidu-int.com' 'nj.wisedebug.baidu-int.com' 'hba.wisedebug.baidu-int.com' 'hnb.wisedebug.baidu-int.com')
arr=($(awk '{print $1}' list_to_run))
i=0
while [ $i -lt ${#arr[@]} ]
do
{
if [ ! -d "$i" ]; then
mkdir "$i"
fi
for j in ${env_list[@]}
do
nohup python3 a.py ${arr[i]} $j &
let i++
echo $i
done
}&
done