Hi there,
i want to use this Linux-script on a Solaris System to check the fragmentation Level of ZFS-DataSets:
#!/bin/sh
zdb -ddddd ${1} | awk --non-decimal-data \
'
/Indirect blocks/ {
file_number++;
next_block = 0;
}
/L0/ {
split($3, fields, ":");
this_block = ("0x"fields[2])+0;
this_block_size = ("0x"fields[3])+0;
total_blocks++;
if( next_block != 0 ) {
if( next_block == this_block ) {
not_fragmented++;
}
else {
fragmented++;
}
}
next_block = this_block + this_block_size;
}
END {
total_fragment_blocks = fragmented + not_fragmented;
printf("There are %d files.\n", file_number );
printf("There are %d blocks and %d fragment blocks.\n", total_blocks, total_fragment_blocks );
printf("There are %d fragmented blocks (%2.2f%%).\n", fragmented, fragmented*100.0/total_fragment_blocks );
printf("There are %d contiguous blocks (%2.2f%%).\n", not_fragmented, not_fragmented*100.0/total_fragment_blocks );
Everything seems to work fine except the conversion from hex to dec at the following lines:
this_block = ("0x"fields[2])+0;
this_block_size = ("0x"fields[3])+0;
I realized, that this is can't be done so easely with Solaris AWK. I found an other NAWK Script on the Internet which can do this but i have no idea how implement this in the main script.
Here is the conversion script:
BEGIN { for(i=0;i<10;i++) decv=i;
decv["a"]=10;decv["b"]=11;decv["c"]=12;decv["d"]=13;
decv["e"]=14;decv["f"]=15;
decv["A"]=10;decv["B"]=11;decv["C"]=12;decv["D"]=13;
decv["E"]=14;decv["F"]=15
}
function hex(x) {
value = 0;
i = 1;
n=length(x);
while ( n > 0 ) {
value = 16*value + decv[substr(x,i,1)];
n--;
i++;
}
return value
}
{printf("%12.0f\n",hex($1))}
Would be great if someone can help me.
Bye
Michael