Linux using multi-threaded batch test site is normal shell

Source: Internet
Author: User

#!/bin/bash# Remove site Data web= ' cat website.txt ' if [-Z ' $web '];then #判断长度如果为0 true. No need to test Web site echo "Data that's not tested" exit 1fitest-f result.log && rm-f result.log #test-F if it's a normal file then true Functi On delay {sleep 3}tmp_fifofile=/tmp/$$.fifo #声明管道名称, ' $$ ' indicates that the script is currently running a process Pidmkfifo $tmp _fifofile #创建管道exec 6<> $tmp _ Fifofile #创建文件标示符 "5", which can be used for all undeclared characters except "0", "1", "2", rm $tmp _fifofile #清除创建的管道文件 # To define the number of concurrent threads, which need to be adjusted according to the VPS configuration. Thread=100for ((i=0;i< $thread; i++)) do echo; #借用read命令一次读取一行的特性, using an echo default output a newline character to ensure that each row has only one thread placeholder; This reminds the producer & Consumer models, Pipeline Files act as message queues to document consumer needs, and then the producer leads the task and completes the task, where the idea of asynchronous decoupling is used. Done>&6 #将占位信息写入管道 # begins a multithreaded loop to detect a for-URL in $webdo read-u6 #从文件描述符管道中, gets the thread placeholder for a pipe and then begins the operation; read-U follows FD, which reads in from the file descriptor , the file descriptor can be newly opened by exec. {#curl抓取网站http状态码 code= ' Curl-o/dev/null--retry 3--retry-max-time 8-s-W%{http_code} $url ' echo ' $code---> $url " >>result.log #判断子线程是否执行成功 and output delay && {echo "$code---> $url"} | | {echo "Check thread error!"} Echo >& 6 #任务执行完后在fd5中写入一placeholder to ensure that the thread continues to occupy after the thread has finished executing, and then maintains that the pipeline is always 100 threads,& indicates that part of the command/task is placed in the background without the current bash, implementing parallel processing}&done# waiting for all threads to execute waitexec 6 >&-#关闭fd6的管道 # Find a site other than 200 return codes echo List of exception Website:cat Result.log | Grep-v 200exit 0

Linux using multi-threaded batch test site is normal shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.