yarn 上运行的任务的简单管理

#!/bin/bash
while [ `ps x |grep -v grep|grep jobTracker.sh |wc -l` -gt 2 ];
do
   echo "jobTracker.sh exited "
   exit
done

while true ;do
    yarn application -list | grep "http://" |grep "RUNNING" |cut -f1,2 |
    while read JOB_LINE;
    do
        T1=`date`
        newTime=`date -d "$T1" +%s`

        JOBID=`echo $JOB_LINE |awk '{print $1}'`
        JOBNAME=`echo $JOB_LINE |awk '{print $2}'`        
        curl --compressed -H "Accept: application/json" -X GET "http://xxx:8088/cluster/app/$JOBID" >./.jobSON.txt
        jobT2=`cat ./.jobSON.txt |grep "+0800 2018" |head -n 1`
        jobStartTime=`date -d "$jobT2" +%s`
        jobRunTime=`expr $newTime - $jobStartTime`
 
        ###job时间超过12600秒的需要被杀掉,即3.5小时
        if (( $jobRunTime > 12600 )) ; then
            yarn application -kill $JOBID
            echo $JOBID "|" $JOBNAME "|" $T1 "|" $jobT2 "|" $jobRunTime >>./listJob_killed.txt
        else
            echo $JOBID "|" $JOBNAME "|" $T1 "|" $jobT2 "|" $jobRunTime
        fi        

    done
    echo "===== 10m -----------"
    sleep 10m
done

猜你喜欢

转载自blog.csdn.net/u010764629/article/details/80774146