Advertisement
Guest User

hard_links_breaker

a guest
Mar 15th, 2011
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.00 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. open LINKS, 'find ' . $ARGV[0]. ' -type f|awk \'{ system("stat -c \"%n %i %a %U:%G %h\" \"" $1 "\""); }\'|egrep \' ([0-9]{2,10}|[2-9])$\'|';
  4. my @links;
  5.  
  6. #Converting to array
  7. for ($i=0;<LINKS>;$i++)
  8. {
  9.     ($links[$i][0], $links[$i][1],$links[$i][2],$links[$i][3],$links[$i][4])=split(' ',$_);
  10. }
  11. printf "Found $i links\n";
  12.  
  13. for (my $i=0;$links[$i];$i++)
  14. {
  15.     $source=$links[$i][0];
  16.     $inode=$links[$i][1];
  17.    
  18.     if ($links[$i][5]) { next; } #Skip corrected
  19.  
  20.     printf "Searching for links of $source (inode $inode)...\n";
  21.    
  22.     for ($j=0;$links[$j];$j++)
  23.     {
  24.     if ($links[$j][1]==$inode && $source ne $links[$j][0])
  25.     {
  26.         $links[$j][5]=1;
  27.         printf "Found: $links[$j][0]\n. Recreating...";
  28.         $a=`rm -rf $links[$j][0]`;#Delete
  29.         #$a.=`echo touch $links[$j][0]`;#Touch
  30.         $a.=`cat $source > $links[$j][0]`;#Copy
  31.         $a.=`chmod $links[$j][2] $links[$j][0]`;
  32.         $a.=`chown $links[$j][3] $links[$j][0]`;
  33.         printf "$a\n";
  34.     }
  35.     }
  36.     #exit;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement