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

来源:互联网 发布:威士忌推荐 知乎 编辑:程序博客网 时间:2024/05/16 09:16
#!/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=1max_2=10000lastchecksum="0"rm -f test.bin_$1 rm -f result_$1.txtwhile [ $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.txtbreak            fi        fi        lastchecksum=$checksumecho "lastchecksum="$lastchecksum        min_1=`expr $min_1 + 1`     fidone