#!/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