Shell script concurrency

Source: Internet
Author: User

#!/bin/bash# filename: bingfa.sh# time: 2016/03/9 18:59:05ip= ' Cat /tmp/iplist '            #  Filter Server ipdir= '/tmp '                  #  Target Path                                   thead_num=10                #  custom concurrency number, depending on the performance of the server or the application to adjust the size, start not to define too large, Avoid management downtime tmp_fifo_file= "/tmp/$$.fifo"        #  name the pipe file with the process ID number mkfifo $ tmp_fifo_file          #  creating a temporary pipeline file exec 4<>$ tmp_fifo_file          #  Open the Tmp_fifo_file pipeline file in read-write mode, The file descriptor is 4, or you can take 3-9 arbitrary descriptor rm -f  $tmp_fifo_file          #  Delete a temporary pipeline file, or you can delete for  (i=0;i < $thead _num;i++)); do    #  use the For loop to enter the number of concurrent lines in the pipeline   echo  ""                 #  Output blank line done > &4                 #   output redirect to the defined file descriptor 4 #  The real command to execute all the commands in the following curly braces for i in  $ip; do            #  cycle all servers to be executed   read -u4                #  reads rows from the pipeline, each row, after all rows have been read, execution hangs until the pipeline has idle rows     {                  #  curly braces are all the commands to execute      echo  $i              #  Display host ip      scp $1  $i: $dir    &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;#&NBSP;SCP is a simple instance where a script is executed to pass in a variable value, replacing any other command and command group       ssh  $i  -n  ' Date '        #  print time       sleep 3            #  pause for 3 seconds, Buffer time to the system, limit the number of concurrent processes      echo  ""  >&4           #  writes a blank line so that the pending loop continues to execute     }&                  #  into the background to execute donewait                    #   Wait for all background processes to complete exec 4>&-                 #&nbSP; Delete file descriptor exit 0 
SH Bingfa.sh/tmp/test.txt # Execute script


This article is from "Walker--->" blog, please be sure to keep this source http://liumissyou.blog.51cto.com/4828343/1749253

Shell script concurrency

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.