in reply to Loop Control
Basically this is my attempt to create a perl script to list size and usage data on subdirectories in my system. This is the template script, my goal is to use Text::CSV to output the data in the arrays @c, @d, & @e into a csv file. Now that I got my first part working, I can go onto part two! I had such a hard time intitially, becuase I was using the output from du -B MB, which would just create variable length strings. If I wanted to I guess I could go that route, but I figured I'd just set the max-depth to 0, to get the values only for the directory i'm evaluating. I know this is a *nix oriented script, eventually I'd like to create something like this to run on windowz. :)#!/bin/perl use strict; use warnings; sub newl { print "\n"; print "\n"; } my @a; my @b; my @c; my @d; my @e; my $na; my @Na; #@a = `df -h | grep mapper | cut -c 48-`; # My original code uses the above statement, but because # this may look different on different shells, I used the # array below @a = ( "/", "/home", "/var", "/tmp", "/var/tmp", "/boot" ) $na = $#a; @Na = ( 0, 1..$na ); for my $i (@Na) { $b[$i] = `ls $a[$i]`; } print @a; newl; for my $i (@Na) { print "\$b[$i] = $b[$i]"; newl; } for (my $i = 0; $i < 1; $i++ ) { my @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = $a[$i]; chomp $z0; $z1 = $c1[$w]; $z2 = $z0 . $z1; #print $z2; newl; push (@c, $z2); }} for (my $i = 1; $i <= 5; $i++ ) { my @c1; @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = "$a[$i]"; chomp $z0; $z1 = "\/$c1[$w]"; $z2 = $z0 . $z1; #print $z2; newl; push (@c, $z2); }} print "\$#c = $#c"; newl; for (my $i = 0; $i <= $#c; $i++ ) { my $y = `du -B MB -d0 $c[$i]`; push (@d, $y); } print "\$#d = $#d"; newl; for (my $i = 0; $i <= $#d; $i++ ) { print "$d[$i]"; newl; } for (my $i = 0; $i < 1; $i++ ) { my @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = $a[$i]; chomp $z0; $z1 = $c1[$w]; $z2 = `ls -last $z0 | grep $z1`; chomp $z2; push (@e, $z2); }} for (my $i = 1; $i <= 5; $i++ ) { my @c1; @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = "$a[$i]"; chomp $z0; $z1 = "$c1[$w]"; $z2 = `ls -last $z0 | grep $z1`; chomp $z2; push (@e, $z2); }} print "\$#e = $#e"; newl; for (my $i = 0; $i <= $#e; $i++ ) { print "$e[$i]"; newl; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Loop Control
by xyzzy (Pilgrim) on Jul 06, 2012 at 02:03 UTC | |
by ateague (Monk) on Aug 02, 2013 at 15:49 UTC |