Grab.pl
Jump to navigation
Jump to search
#!/usr/bin/perl $tmpfile = "/tmp/ib.txt"; open(OUT, ">test.dot"); @output = `ssh -x submit ibnetdiscover --switch-map ib.map`; for ($i=0; $i<=$#output; $i++) { @fields = split(/\s+/, @output[$i]); @vendid = split(/=/, @fields[0]); if (@fields[0] eq 'Switch') { $n1 = @fields[4]; $switch=1; next; } if (@vendid[0] eq 'vendid') { $switch=0; $n1 = ""; } if ($switch && @fields[3]) { $n2 = @fields[3]; $n1 =~ s/\"//g; $n2 =~ s/\"//g; $n1 =~ s/\-/_/g; $n2 =~ s/\-/_/g; @n1 = split(/\./, $n1); @n2 = split(/\./, $n2); if (@n1[0] && @n2[0]) { print OUT "\t" . @n1[0] . " -> " . @n2[0] . ";\n"; } } } close(OUT); system ("cat test.dot | sort -r | uniq > test.sorted"); open (OUT, ">test.dot"); print OUT "digraph G {\n"; print OUT "\trankdir = LR;\n"; print OUT "\tranksep = \"2.0\";\n"; print OUT "\t{ rank = same;\n"; print OUT "\t \"ib9601\"; \"ib9602\";\n"; print OUT "\t};\n"; close (OUT); system ("cat test.sorted >> test.dot"); system ("echo '}' >> test.dot"); system ("dot -Tgif test.dot -o graph.gif"); system ("rm test.dot test.sorted");