summaryrefslogtreecommitdiffstats
path: root/frag.pl
diff options
context:
space:
mode:
authorFlorian Pritz <f-p@gmx.at>2008-10-23 19:52:30 +0200
committerFlorian Pritz <f-p@gmx.at>2008-10-23 19:52:30 +0200
commitc597b01166c4ac4d042c2256826b69c6fb0bc405 (patch)
tree72f0971a761070273b625650c7cb40149db02ef7 /frag.pl
downloadbin-c597b01166c4ac4d042c2256826b69c6fb0bc405.tar.gz
bin-c597b01166c4ac4d042c2256826b69c6fb0bc405.tar.xz
first init
Diffstat (limited to 'frag.pl')
-rwxr-xr-xfrag.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/frag.pl b/frag.pl
new file mode 100755
index 0000000..b8eb685
--- /dev/null
+++ b/frag.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl -w
+
+#this script search for frag on a fs
+use strict;
+
+#number of files
+my $files = 0;
+#number of fragment
+my $fragments = 0;
+#number of fragmented files
+my $fragfiles = 0;
+
+#search fs for all file
+open (FILES, "find " . $ARGV[0] . " -xdev -type f -print0 |");
+
+$/ = "\0";
+
+while (defined (my $file = <FILES>)) {
+ open (FRAG, "-|", "filefrag", $file);
+ my $res = <FRAG>;
+ if ($res =~ m/.*:\s+(\d+) extents? found/) {
+ my $fragment = $1;
+ $fragments += $fragment;
+ if ($fragment > 1) {
+ $fragfiles++;
+ }
+ $files++;
+ } else {
+ print ("$res : not understand for $file.\n");
+ }
+ close (FRAG);
+}
+close (FILES);
+
+print ( $fragfiles / $files * 100 . "% non contiguous files, " . $fragments / $files . " average fragments.\n"); \ No newline at end of file