spark作业清理脚本 留存备用

B站影视 2024-12-26 18:49 1

摘要:if [[ "$result1" != "" || "$result2" != "" ]]

#!/bin/bash

WORK_HOME=$(cd "$(dirname "$0")"; pwd)

cd $WORK_HOME

umask 077

INSTALL_DIR=$WORK_HOME/..

SPARK_WORK_PATH=$INSTALL_DIR/spark/work

if [[ -f running_apps.txt ]];then

rm -rf running_apps.txt

fi

if [[ -f running_drivers.txt ]];then

rm -rf running_drivers.txt

fi

source ./props.sh ./config.properties

SPARK_MASTER_ADDR=${SPARK_SPARK_MASTER_ADDR}

curl -XGET http://$SPARK_MASTER_ADDR/ > result.txt

COMPLETED_APP_FLAG="0"

COMPLETED_DRIVERS_FLAG="0"

RUNNING_APP_FLAG="0"

RUNNING_DRIVER_FLAG="0"

cat result.txt | while read line

do

if [[ "$RUNNING_APP_FLAG" == "1" ]]

then

#echo "get completed applications ids"

#appresult=$(echo $line | grep -E "app-[0-9]{14}-[0-9]{4}")

appresult=$(expr "$line" : '.*\(app-[0-9]*-[0-9]*\).*')

if [[ "$appresult" != "" ]]

then

echo $appresult

echo $appresult >> running_apps.txt

fi

fi

if [[ "$RUNNING_DRIVER_FLAG" == "1" ]]

then

#echo "get completed driver ids"

appresult=$(expr "$line" : '.*\(driver-[0-9]*-[0-9]*\).*')

then

echo $appresult

echo $appresult >> running_drivers.txt

fi

fi

if [[ "$COMPLETED_APP_FLAG" == "1" ]]

then

then

echo $appresult

#echo $appresult >> completed_apps.txt

rm -rf $SPARK_WORK_PATH/$appresult

fi

fi

if [[ "$COMPLETED_DRIVERS_FLAG" == "1" ]]

then

then

echo $appresult

#echo $appresult >> completed_drivers.txt

fi

fi

result=$(echo $line | grep "Running Applications")

if [[ "$result" != "" ]]

then

echo "$line"

RUNNING_APP_FLAG="1"

fi

result=$(echo $line | grep "Running Drivers")

if [[ "$result" != "" ]]

then

echo "$line"

RUNNING_DRIVER_FLAG="1"

RUNNING_APP_FLAG="0"

fi

result=$(echo $line | grep "Completed Applications")

then

echo "$line"

COMPLETED_APP_FLAG="1"

RUNNING_DRIVER_FLAG="0"

fi

result=$(echo $line | grep "Completed Drivers")

then

echo $line

COMPLETED_DRIVERS_FLAG="1"

COMPLETED_APP_FLAG="0"

fi

rm -rf result.txt

if [[ ! -f running_apps.txt ]];then

echo "this is an error: not exist running_apps.txt"

exit 1

fi

if [[ ! -f running_drivers.txt ]];then

exit 1

fi

dirs=`ls ${SPARK_WORK_PATH}`

for dir in $dirs

do

echo $dir

result1=$(cat running_apps.txt | grep "$dir")

result2=$(cat running_drivers.txt | grep "$dir")

if [[ "$result1" != "" || "$result2" != "" ]]

then

echo "this is a running app or driver: $dir"

else

echo "this is not a runnint app and is not a running driver:$dir"

rm -rf $SPARK_WORK_PATH/$dir

fi

rm -rf running_apps.txt

rm -rf running_drivers.txt

echo "Process end"

来源:小轩科技园地

相关推荐