Need some ideas here. I was using something along the lines of if $[$x-$y>1500] then etc.... to detect the size of the changes to a file. I've realized that won't work as the files sizes could increase or decrease which could result in a negative number. Is there a way to use absolute value of x-y?
2 Answers
I have done this. I create a new file (with at ".new" suffix) but before replacing the old I would check the size difference of the files, and abort (sending some type of notification, such as mail) if there are too many changes.
I generally do this in perl, but bash would be similar.
$file="file_being_updated";
$new=".new";
if ( -f $file ) {
my $percent_diff = abs( 100 - 100*(-s "$file$new")/(-s $file) );
if ( $percent_diff > 20 ) { # more that this to different!
printf STDERR "File \"$file$new\" differs by more that 20%%! (%.1f%%)\n", $percent_diff;
printf STDERR "-------------- ABORTING REPLACMENT -----------\n";
exit 10;
}
}
diff=$((x - y)
diff=$(( (diff > 0) ? $diff : -1*$diff ))
if [ $diff -gt 1500 ]
then
echo do something
fi