shell多线程

shell用rsync同步500G太慢,用iptop看了io还没有满,负载也不是很高,

因为服务器配置比较高,想起了多线程,

#!/bin/bash

cd /data/test/

thead_num=50

tmp_fifo_file="/tmp/$$.fifo"

mkfifo $tmp_fifo_file

exec 4<>$tmp_fifo_file

rm -f $tmp_fifo_file

for ((i=0;i<$thead_num;i++))

do

        echo ""

done >&4

for dir in `ls -F |grep "/"|sed -n '/^[j-z]/p'|sed 's/\///g'`

do

        read -u4

                {

                sudo -u  www rsync -avzrtopgL --progress /data/test/$dir test1:/data/test/ >>/data/test5.log

                sleep 3

                        echo "" >&4

                }&

done

wait

exec 4>&-

exit 0



你可能感兴趣的:(Shell多线程)