From 6754e3902c3c1ee41408ab6f780e1dcac954a00b Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 30 Mar 2016 10:19:31 -0400 Subject: [PATCH] Modify split code as per XiaoPeng's comments --- xCAT-server/lib/xcat/plugins/switchdiscover.pm | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index fbc7507ee..cde703e9d 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -666,12 +666,8 @@ sub nmap_scan { ################################################# #display the raw output ################################################# - if (exists($globalopt{r})) { + if (defined($globalopt{r}) || defined($globalopt{verbose})) { send_msg($request, 0, "$result\n" ); - } else { - if (exists($globalopt{verbose})) { - send_msg($request, 0, "$result\n" ); - } } ################################################# @@ -839,18 +835,16 @@ sub snmp_scan { ################################################# #display the raw output ################################################# - if (exists($globalopt{r})) { + if (defined($globalopt{r}) || defined($globalopt{verbose})) { send_msg($request, 0, "$result\n" ); - } else { - if (exists($globalopt{verbose})) { - send_msg($request, 0, "$result\n" ); - } } my @lines = split /\n/, $result; + # each line like this: "Discovered open port 161/udp on 10.4.25.1" # only open port will be scan foreach my $line (@lines) { - my $ip = `echo "$line\n" |awk '{printf \$6}'`; + my @array = split / /, $line; + my $ip = $array[5]; if (exists($globalopt{verbose})) { send_msg($request, 0, "Run snmpwalk command to get information for $ip"); }