Answer the question
In order to leave comments, you need to log in
How to handle system result in perl script?
The perl script has a function call
system("/usr/sbin/ipset -A $table_name $ip");
sometimes it returns
ipset v4.5: 194.186.2.46 is already in set autoban_31.
in this case I need to execute
system("/usr/sbin/ipset -A $higher_table_name $ip");
Answer the question
In order to leave comments, you need to log in
The return value of system is the error code shifted 8 bits to the left. If ipset in the described situation returns some specific code, you can pull it out and process it. If not, then just parse the output string, replacing system with backticks, as PooFF suggested above .
In addition to what PooFF wrote, I can recommend that you check the return code, in case of an error while executing the script that you do not know (do not know what to parse in the output) ...
Example:
my $command = "/usr/sbin/ipset -A $table_name $ip";
my @result =`$command`
foreach my $line (@result)
{
if ($line =~ /already\sin\sset\sautoban_31/) {
system("/usr/sbin/ipset -A $higher_table_name $ip");
}
die("Unknown error. Command ".$command." return code: ".$?."") if $? -ne 0 ;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question