bash实现线程池,动态分析页面

2024-01-03 09:58

本文主要是介绍bash实现线程池,动态分析页面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

#总结来说,bash实现方便但是没有锁,是的实现过于晦涩,打算使用python改写之


#!/bin/bashdeclare -a SDM=($@) #inputdeclare -a printArray=() #no use nowdeclare -a printKey=() #avoid dead circledeclare -a thread_pid=() #multhreadexport threadNum=30export bexistFlag=0export filename="$1.status.txt"export tempsubdir="$1.subdir"export mtfilename="$tempsubdir/$1.status"export dbfilename="$tempsubdir/$1.debug"export begin_time=""export end_time=""function fetch(){ for loop in $@ do for loop1 in ${printKey[@]} do if [ "$loop1" = "$loop" ];then bexistFlag=1 break fi done if [ "$bexistFlag" = "1" ];then bexistFlag=0 continue fi#rm -fr ${tempsubdir}/${loop}.txt if [ ! -e ${tempsubdir}/${loop}.txt ];then curl -s -u tailianl:1qazxsw@ https://atlassianwave.web.alcatel-lucent.com/jira/browse/${loop} -o ${tempsubdir}/${loop}.txt elif [ -s ${tempsubdir}/${loop}.txt ];then echo "${loop}.txt exist once" >> ${dbfilename}.$! sleep 1 else echo "${tempsubdir}/${loop}.txt size is 0" >> ${dbfilename}.$! while [ 1 ]; do if [ -s ${tempsubdir}/${loop}.txt ];then echo "${loop}.txt wait for done" >> ${dbfilename}.$! sleep 1 break else echo "${loop}.txt wait for exist" >> ${dbfilename}.$! sleep 1 fi done fi # echo ""echo -n "---$loop---" echo "----------------------$loop----------------------------" >>${dbfilename}.$! #linkJira=`cat ${loop}.txt | grep "data-issue-key" | grep -v "div" | awk -F= '{print $3}' | awk '{print $1}' | awk '{print $1}'|sort -u|awk -F\" '{print $2}'|grep SDM` checkVliad priority=`cat ${tempsubdir}/${loop}.txt | grep priorities | grep -v class | awk '{print $2}' | awk -F= '{print $2}'|awk -F\" '{print $2}'` isfixed=`cat ${tempsubdir}/${loop}.txt | grep fixforversion | awk -F">" '{print $2}' | awk -F"<" '{print $1}'` firstStatus=`cat ${tempsubdir}/${loop}.txt | grep -n "jira-issue-status-lozenge" | awk '{print $1}'` nowVersion $firstStatus theStatus=`cat ${tempsubdir}/${loop}.txt | grep -n jira-issue-status-lozenge | grep "$theVersion" | awk -F\> '{print $2}'|awk -F\< '{print $1}'` printKey=(${printKey[@]} $loop) #echo ${printKey[@]} printArray=(${printArray[@]} "$loop $priority $isfixed") if [ "$isfixed" != "" ];then #printf "%-10s%-10s%-15s%10s\n" $loop $isfixed $theStatus $priority >> status.txt echo "$lline#$loop#$isfixed#$theStatus#$priority" >> $mtfilename.$! fetch $linkJira fi done return 0}function checkVliad(){#echo $@ declare -a numDuplicate=(`cat ${tempsubdir}/${loop}.txt | grep -n "dt title"| grep -i duplicate|awk -F: '{print $1}'`)#echo $numDuplicate if [ ${#numDuplicate[@]} -eq 0 ];then linkJira=`cat ${tempsubdir}/${loop}.txt | grep "data-issue-key" | grep -v "div" |grep SDM| grep issue-link | grep link-title| awk -F= '{print $3}' | awk '{print $1}' | awk '{print $1}'|sort -u|awk -F\" '{print $2}'` echo "linkJira: $linkJira" >> ${dbfilename}.$! else declare -a checkDuplite=(`cat ${tempsubdir}/${loop}.txt| grep -n "dt title" | awk -F: '{print $1}'`) uplevel=20000 downlevel=0#echo ${#checkDuplite[@]}# echo ${checkDuplite[@]} for (( j=0; j < ${#numDuplicate[@]}; j++ )) do for (( i=0; i < ${#checkDuplite[@]}; i++ )) do# echo ${numDuplicate[$j]} ${checkDuplite[$i]} if [ ${numDuplicate[$j]} -ge ${checkDuplite[$i]} ];then downlevel=${checkDuplite[$i]} # echo "downlevel=${checkDuplite[$i]}" fi if [ ${numDuplicate[$j]} -lt ${checkDuplite[$i]} ];then uplevel=${checkDuplite[$i]}# echo "uplevel=${checkDuplite[$i]}" break fi done done declare -a linkJiraIndex=(`cat ${tempsubdir}/${loop}.txt |grep -n "data-issue-key" | grep -v div | grep SDM| grep issue-link | grep link-title|awk -F: '{print $1}'`) declare -a linkJiraTmp=(`cat ${tempsubdir}/${loop}.txt | grep "data-issue-key" | grep -v "div" |grep issue-link | grep link-title|grep SDM| awk -F= '{print $3}' | awk '{print $1}' | awk '{print $1}'|awk -F\" '{print $2}'`) j=0# echo "$downlevel $uplevel" linkJira=""# echo ${linkJiraIndex[@]}# echo ${linkJiraTmp[@]}# echo $downlevel $uplevel for loop4 in ${linkJiraIndex[@]} do# echo $j if [ $loop4 -lt $downlevel -o $loop4 -gt $uplevel ];then # echo $downlevel $loop4 $uplevel linkJira="${linkJiraTmp[$j]} $linkJira" fi ((++j)) done echo "this is duplicate Jira:---" >> ${dbfilename}.$! echo "down and up: $downlevel $uplevel" >> ${dbfilename}.$! echo "linkJiraIndex: ${linkJiraIndex[@]}" >> ${dbfilename}.$! echo "linkJiraTmp: ${linkJiraTmp[@]}" >> ${dbfilename}.$! echo "numDuplicate: ${numDuplicate[@]}" >> ${dbfilename}.$! echo "checkDuplite: ${checkDuplite[@]}" >> ${dbfilename}.$! echo "linkJira: ${linkJira[@]}" >> ${dbfilename}.$! fi return 0}function do_fetch(){ thread_pid=() for loop2 in $@ do for lline in `cat $loop2` do #fetch $lline subprocess $lline printKey=() done done while [ ${#thread_pid[@]} -ne 0 ]; do for pid_idx in ${!thread_pid[*]}; do pid_val=${thread_pid[$pid_idx]} if [ ${#pid_val} -ne 0 ]; then kill -s 0 $pid_val &>/dev/null [ $? -ne 0 ] && unset thread_pid[$pid_idx] fi done done return 0}function nowVersion(){ theVersion=$1 return 0}function formatPrint(){#rm -fr docollect.sh#echo "#!/bin/bash" > docollect.sh#echo "cat ${mtfilename}.* > ${filename}" >> docollect.sh#chmod u+x docollect.sh#echo "please run docollect.sh after analys!!!!!!!!" cat ${mtfilename}.* > ${filename} cat ${dbfilename}.* > ${dbfilename} end_time=`date` echo "end_time: $end_time" >> ${dbfilename} echo "--------------------------------------------" echo "---Begin time: $begin_time" echo "---End time: $end_time" echo "--------------------------------------------" echo "--------------------------------------------" echo "the result file is : ${filename}" echo "the debug file is : ${dbfilename}" echo "--------------------------------------------" return 0}function hello_thread(){ echo "hello" sleep $1 echo "end hello"}function subprocess(){ while [ 1 ]; do if [ ${#thread_pid[@]} -lt ${threadNum} ]; then fetch $1 & #hello_thread 5 & thread_pid=("${thread_pid[@]}" "$!") break else for pid_idx in ${!thread_pid[*]}; do pid_val=${thread_pid[$pid_idx]} if [ ${#pid_val} -ne 0 ]; then kill -s 0 $pid_val &>/dev/null [ $? -ne 0 ] && unset thread_pid[$pid_idx] fi done fi done}function main(){ begin_time=`date` trap "kill -9 $$" SIGINT rm -fr $filename rm -fr $tempsubdir rm -fr $dbfilename mkdir -p $tempsubdir#formatPrint echo "begin_time: $begin_time" > ${dbfilename} do_fetch $@ formatPrint return 0}echo $@main $@

这篇关于bash实现线程池,动态分析页面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/565325

相关文章

Linux线程同步/互斥过程详解

《Linux线程同步/互斥过程详解》文章讲解多线程并发访问导致竞态条件,需通过互斥锁、原子操作和条件变量实现线程安全与同步,分析死锁条件及避免方法,并介绍RAII封装技术提升资源管理效率... 目录01. 资源共享问题1.1 多线程并发访问1.2 临界区与临界资源1.3 锁的引入02. 多线程案例2.1 为

分布式锁在Spring Boot应用中的实现过程

《分布式锁在SpringBoot应用中的实现过程》文章介绍在SpringBoot中通过自定义Lock注解、LockAspect切面和RedisLockUtils工具类实现分布式锁,确保多实例并发操作... 目录Lock注解LockASPect切面RedisLockUtils工具类总结在现代微服务架构中,分布

Java使用Thumbnailator库实现图片处理与压缩功能

《Java使用Thumbnailator库实现图片处理与压缩功能》Thumbnailator是高性能Java图像处理库,支持缩放、旋转、水印添加、裁剪及格式转换,提供易用API和性能优化,适合Web应... 目录1. 图片处理库Thumbnailator介绍2. 基本和指定大小图片缩放功能2.1 图片缩放的

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连

Python实现网格交易策略的过程

《Python实现网格交易策略的过程》本文讲解Python网格交易策略,利用ccxt获取加密货币数据及backtrader回测,通过设定网格节点,低买高卖获利,适合震荡行情,下面跟我一起看看我们的第一... 网格交易是一种经典的量化交易策略,其核心思想是在价格上下预设多个“网格”,当价格触发特定网格时执行买

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

Python对接支付宝支付之使用AliPay实现的详细操作指南

《Python对接支付宝支付之使用AliPay实现的详细操作指南》支付宝没有提供PythonSDK,但是强大的github就有提供python-alipay-sdk,封装里很多复杂操作,使用这个我们就... 目录一、引言二、准备工作2.1 支付宝开放平台入驻与应用创建2.2 密钥生成与配置2.3 安装ali

Spring Security 单点登录与自动登录机制的实现原理

《SpringSecurity单点登录与自动登录机制的实现原理》本文探讨SpringSecurity实现单点登录(SSO)与自动登录机制,涵盖JWT跨系统认证、RememberMe持久化Token... 目录一、核心概念解析1.1 单点登录(SSO)1.2 自动登录(Remember Me)二、代码分析三、

PyCharm中配置PyQt的实现步骤

《PyCharm中配置PyQt的实现步骤》PyCharm是JetBrains推出的一款强大的PythonIDE,结合PyQt可以进行pythion高效开发桌面GUI应用程序,本文就来介绍一下PyCha... 目录1. 安装China编程PyQt1.PyQt 核心组件2. 基础 PyQt 应用程序结构3. 使用 Q