Jenkins运行服务器脚本,自动打印日志捕获关键字自动退出
python update_server.py | sed '/启动成功.../q'
使用sed 命令搜索关键字 进行退出
或者配合 timeout
timeout 15s python update_server.py | sed '/启动成功.../q'
这样等待15秒后会直接杀掉进程,可能会导致任务没有启动或者执行一半中断
1 #!/bin/bash 2 echo `pwd` 3 cd app/server 4 if [ $module == 'business' ]; then 5 cd learn-self-business 6 sh kill.sh 7 sleep 3 8 rm -f learn-self-business.jar 9 cp ../jenkins/learn-self-business.jar . 10 sh startup.sh 11 sleep 35 12 cat nohup.out | tail -n 100 13 echo "启动时间: `awk '/Started LearnSelfBusinessApplication in/{print $15}' ./nohup.out`" 14 start_status=`awk '/Started LearnSelfBusinessApplication in/{print ($15~/^[-]?([0-9])+[.]?([0-9])+$/)?"ok":"error"}' ./nohup.out` 15 echo $start_status 16 if [ $start_status == 'ok' ]; then 17 exit 0 18 else 19 exit 1 20 fi 21 fi
本文来自博客园,作者:margo,转载请注明原文链接:https://www.cnblogs.com/ZMargo/articles/15036309.html