The below script has Perl script in it where it gives the usage details.
filer.sh
echo
echo -en "Enter filer : "
read filer
echo "test.pl -f $filer -F L"
Output
The following hosts are online and available:
Name Total Allocated Used Available Allocated % Used %
-----------------------------------------------------------------------------------------------
pool1 25984 GB 25486 GB 14745 GB 11238 GB 98 % 57 %
Enter the name of the pool you want to use:
In the above output I need to press ctrl-c to come our of perl script.
Could anyone help me modifying the script so that the script should come out shell script without pressing the ctrl-c
Include the exit scenario in test.pl
perl script .. Post the code of it ..
Here is the code for perl script.
The perl script is inbuilt script which I am using to list pools
(LP) List Pools
Below is the code of perl
Enter the action you would like to perform: ';
chomp ($opt{F} = <STDIN>);
# $opt{F} = uc($opt{F});
} until ($opt{F} =~ m/^A$|^M$|^R$|^D$|^L$|^LP$|^Lp$|^Ls$|^LS$|^CS$|^DS$|^RS$|^C$|^B$/);
return;
}
# Validate a pool supplied on the cmd line
sub _validate_pool {
my ($args) = shift;
# $args->{pools} => the pool data from the filer.
# $args->{pool_to_check} => The pool to verify.
# Go through the pool data and if the pool_to_check matches the data pulled from the filer.
foreach my $pool_data (@{ $args->{pools} }) {
# if ($pool_data =~ m/^$args->{pool_to_check}\s+/ && $pool_data =~ m/\s+online\s+/) {
if ($pool_data =~ m/^$args->{pool_to_check}\s+/) {
return 1;
}
}
print "\nWARNING: Invalid pool specified\n\n";
return 0;
}
# If the user doesn't specify the pool
sub _get_pool {
my $ref = shift;
my @pools = @{ $ref };
my $input;
do {
print "\nThe following pools are online and available:\n";
printf("%-10s %10s %10s %10s %10s %10s %% %10s %%\n", "Name", "Total", "Allocated", "Used", "Available", "Alloca ted", "Used");
print("-"x95);
print "\n";
foreach my $pool (@pools) {
my (@data) = split(/\s+/, $pool);
# if ($data[5] eq "online") {
printf("%-10s %10d GB %10d GB %10d GB %10d GB %10d %% %10d %%\n", $data[0], $data[1] / 1048576, $data[2] / 1 048576, $data[3] / 1048576, $data[4] / 1048576, $data[5], $data[6]);
# }
}
print "\nEnter the name of the pool you want to use: ";
chomp ($input = <STDIN>);
} until ( &_validate_pool({pools => $ref, pool_to_check => $input}));
return $input;
}