#!/usr/local/bin/perl use strict; use warnings; use List::Util; use lib "/git_scripts/lib"; use gitadm_general_tools(); use gitadm_logparse_commands(); use gitadm_shell_commands(); my (@data_volumes,@error_log,@size,@partitions); my $storage_broken = gitadm_shell_commands::select_storage(); my $storage = select_storage(); print "$storage \n"; sub error { # Stores strings passed to it for later use in logging and emails my @strs = shift; for my $string(@strs) { push @error_log, "$string\n"; } } sub select_storage { my $known = shift; my $fstab = "/etc/fstab"; my ($percent,$check); my $use = "none"; # Replaced with file path if < $lowest my $lowest = "95"; # Blocks repo creation if value is >= 95 # Detect known or best volume to use for repo creation if (not $known) { open my $VOLUMES,'<', $fstab or die "$!"; @partitions = <$VOLUMES>; } else { push(@partitions, $known); } @partitions = grep/data/, @partitions; for my $p(@partitions) { my @parse_volumes = split(' ', $p); my @volume = grep/data/, @parse_volumes; push(@data_volumes, @volume); } for my $d(@data_volumes) { my $df_out = `/bin/df $d`; my @space = split(' ', $df_out); @space = grep(/\d/, @space); @space = grep/%/, @space; @space = grep(defined, @space); for my $s(@space) { my @percentages = split('%', $s); my @precentages = grep(defined, @percentages); $check = join("",@percentages); if ("$check" < "$lowest") { $lowest = "$check"; $use = $d; } } } if ($use eq "none") { error("Insuffcient storage available to create the requested repository"); } else { return $use; } }