I have a small Perl script that is used to take user command line input, and then splitting the input into an array where each service should be its own element.
My goal is to enable single arguments, as well as several arguments using a split character where every argument is separated by a comma sign. Examples of these would be:
- ssh
- ssh,named,cups
My code looks as follows, it does compile without errors but the output is not the intended.
print "Please provide the service name that you wish to analyze (Named service):\n";
print "Several services may be provided, using a comma sign as a separator.\n";
my $service_name_input = <>;
chomp($service_name_input);
my @service_list = split(/,/, $service_name_input);
foreach my $line (@service_list)
{
open(my $service_input, "service @service_list status|");
}
foreach my $line (@service_list)
{
#Matches for "running".
if ($line =~ m/(\(running\))/)
{
print "The service @service_list is running\n";
}
#Matches for "dead".
elsif ($line =~ m/(dead)/)
{
print "The service @service_list is dead\n";
}
}
The program should output if the service is running or dead, but I only get the following error code. When manually issuing the service command, it works just fine though.
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
Any help regarding the steps I should take in order to achieve a working program will be much appreciated. Thank you for reading.
open(my $service_input, "service @service_list status|");->open(my $service_input, "service $line status|");$service_inputaside from opening it. You might want to capture the output somehow.