多线程核对MD5码:
#!/bin/bash
read -p "请输入需要核对MD5码的文件具体路径(例:/data/1.txt):" file
if [ -f $file ]
then
echo "此中心MD5码 `/usr/bin/md5sum $file`" >md5.txt
else
echo "中心不存在此文件,请再次确认··"
exit 1
fi
thead_num=10
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 i in `cat ip.txt`
do
read -u4
{
echo "$i `ssh root@$i /usr/bin/md5sum $file`" >> md5.txt
sleep 3
echo "" >&4
}&
done
wait
exec 4>&-
# exit 0
#for i in `cat ip.txt`
#do
#echo "$i `ssh root@$i /usr/bin/md5sum $file`" >> md5.txt
#done
a=`awk 'NR==1 {print $2}' md5.txt`
b=`grep -v "$a" md5.txt|wc -l`
if [ $b -eq 0 ]
then
echo "md5码核对全部正确:"
cat md5.txt
else
echo "失败的为:"
echo `grep -v "$a" md5.txt`
echo ""
echo "=================================================================="
echo "成功的为:"
cat md5.txt |grep "$a"
fi