linux-shell 脚本

检查文件是否生成成功

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值