如果命令运行超过1分钟,我想停止该命令,然后继续运行下一条命令。
for((part=0;part<=100;part++));
do
spark-submit \
--verbose \
--master yarn \
--deploy-mode cluster \
--conf spark.pyspark.python=myenv/bin/python3 \
python_demo.py $part
done
命令spark-submit
将我的代码提交给yarn。成功提交后,它将一直运行,直到代码ython_demo.py
停止为止。但是现在我想如果提交成功则继续提交。
现在,shell运行起来就像:
spark-submit -> submit successfully (about 1 minutes)-> run python_demo.py(it will run for a long time) -> spark-submit next part
预期:
spark-submit -> if run more than 1 minutes(It means a successful submission)-> spark-submit next part
答案 0 :(得分:2)
使用超时命令,您可以执行以下操作:
for((part=1;part<=100;part++))
do
timeout 60 2>/dev/null spark-submit \
--verbose \
--master yarn \
--deploy-mode cluster \
--conf spark.pyspark.python=myenv/bin/python3 \
python_demo.py $part
if [[ $? != 0 ]]
then
break
else
continue
fi
done