随机读取文件做算checksum shell 脚本

#!/bin/sh
## usage:  sh test_cp.sh  20 1024
## 
rand(){
    min=$1    
    max=$(($2-$min+1))    
    #num=$(date +%s)
    num=$(cat /proc/sys/kernel/random/uuid|cksum|cut -f1  -d" ")
    echo $(($num%$max+$min))     
 }
min_1=1
max_2=10000
lastchecksum="0"
rm -f test.bin_$1 
rm -f result_$1.txt
while [ $min_1 -le $max_2 ]
do
    rnd=$(rand 1 102400)
    if [ "$rnd" -gt "0" ]
    then
        echo "rand: "$rnd >>result_$1.txt
        rm -f test.bin_$1 
        dd if=bin_file of=test.bin_$1 skip=$rnd count=$1 bs=$2
        checksum=`echo $(cat test.bin_$1|cksum)|cut -f1  -d" "`
		echo "checksum:"$checksum >>result_$1.txt
        if [ $lastchecksum != "0" ];then
            if [ $checksum != $lastchecksum ];then
			    echo $checksum >> result_$1.txt
                echo "checksum error" >> result_$1.txt
				break
            fi
        fi
        lastchecksum=$checksum
		echo "lastchecksum="$lastchecksum
        min_1=`expr $min_1 + 1`
     fi
done  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值