Advertisement
munsking

perl filecheck for .bashrc

Jun 17th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.89 KB | None | 0 0
  1. fileCheck() {
  2.   perl -e '
  3.  use Digest::MD5 qw(md5);
  4.  $file = shift; die "no file [$file]" unless -f $file;
  5.  $compFile = shift; $compFile = 0 unless -f $compFile;
  6.  $sleep = 1;
  7.  sleep $sleep;
  8.  if($compFile ne 0){
  9.    $format = "%0.2fM   \t %0.2fM   \t %.2f%%\n";
  10.  }else{
  11.    $format = "%0.2f %0.2f\n";
  12.  }
  13.  $counter = 1;
  14.  while(1){
  15.    $size = ((stat($file))[7]);
  16.    if($lastsize != $size){
  17.      $counter = 1;
  18.    }else{
  19.      $counter--;
  20.      if($counter <= 0){
  21.        print "\n\nCopy/loading/whatever finished\n";
  22.        if($compFile ne 0){
  23.          print "starting checksum...\n";
  24.          open FILE, $file;
  25.          binmode FILE;
  26.          $data = <FILE>;
  27.          close FILE;
  28.          $chkFile = md5($data);
  29.          open FILE, $compFile;
  30.          binmode FILE;
  31.          $data = <FILE>;
  32.          close FILE;
  33.          $chkComp = md5($data);
  34.          print "\n$chkFile\n$chkComp\n";
  35.          if($chkFile eq $chkComp){
  36.            print "seems legit\n";
  37.          }else{
  38.            print "something might be wrong\n";
  39.          }
  40.        }
  41.        
  42.        my $hash;
  43.        {
  44.            local $/ = undef;
  45.            open FILE, "$wav_file_name";
  46.            binmode FILE;
  47.            my $data = <FILE>;
  48.            close FILE;
  49.            $hash = md5($data);
  50.        }
  51.        
  52.        exit;
  53.      }
  54.      next;
  55.    }
  56.    $change = $size - $lastsize;
  57.    if($compFile ne 0){
  58.      $compSize = ((stat($compFile))[7]);
  59.      $compPerc = $size / ( $compSize / 100);
  60.    }
  61.    printf $format, $size/1024/1024, $change/1024/1024/$sleep, ($compFile ne 0 ? $compPerc : null);
  62.    sleep $sleep;
  63.    $lastsize = $size;
  64.  }' "$1" "$2"
  65. }
  66.  
  67. mcp(){
  68.   if [ ! -f $1 ]; then
  69.     echo "File $1 not found!"
  70.     exit
  71.   else
  72.     src=$1
  73.   fi
  74.   if [ -d $2 ]; then
  75.     dst="$2$(basename $1)"
  76.   else
  77.     dst=$2
  78.   fi
  79.   cp $src $dst &
  80.   fileCheck $dst $src
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement