#!/usr/bin/env perl $FILE="/etc/mnttab"; open FILE or die "Can't open $FILE: $!"; while () { chomp; ($lv, $fs) = split; push @mnttab, ($lv, $fs) } %mnttab = @mnttab; open(LVM, "vgdisplay -Fv |") || die "Can't fork vgdisplay: $!"; while () { chomp; $h_ref = {}; %{ $h_ref } = split(/[=:]/); if ( $h_ref->{vg_name} && $a_ref->[0]->{vg_name} ) { push @vgdisplay, $a_ref; $a_ref = () } delete $a_ref->[0] unless ( %{ $a_ref->[0] } ); push @{ $a_ref }, $h_ref } push @vgdisplay, $a_ref if ref($a_ref); for $i ( @vgdisplay ) { print "Detected VG: $i->[0]->{vg_name}\n"; print "The PE size is: $i->[0]->{pe_size}\n"; $count = 2*$i->[0]->{pe_size}; for ( $j = 1; $i->[$j]->{lv_name}; $j++ ) { next unless defined $mnttab{$i->[$j]->{lv_name}}; print "Detected LV: $i->[$j]->{lv_name}\t"; print "The LV is mounted on: $mnttab{$i->[$j]->{lv_name}}\n"; print "Changing directory to the $mnttab{$i->[$j]->{lv_name}}/lost+found\n"; chdir "$mnttab{$i->[$j]->{lv_name}}/lost+found" or warn "Can't cd to $mnttab{$i->[$j]->{lv_name}}/lost+found: $!\n" and next; print "Creating the dummy file: dummy\n"; !system "dd if=/dev/zero of=dummy bs=1024k count=$count" or warn "Can't dd to file dummy\n"; } # for ( ; $i->[$j]->{pv_name}; $j++ ) { # print "Detected PV: $i->[$j]->{pv_name}\n"; # } print "########################################\n"; } close(LVM) || die "Can't close vgdisplay: $!";