1
我有一個數組公開了來自rooter cisco命令的輸出的數組show ip bgp summary
;這個命令顯示used/active/idle /等。連接在bgp連接。匹配具有一定範圍的時間值的行
陣列看起來像:
[router_name] =>
8.8.8.8 4 54332 0 0 0 0 0 never Active
4.4.4.4 4 14432 0 0 0 0 0 never Active
1.1.1.1 4 53222 0 0 0 0 0 never Active
3.2.54.3 4 64323 9743 9236 0 0 0 3d14h Idle (Admin)
60.34.22.56 4 99999 8434 9214 0 0 0 3d14h Idle (Admin)
43.22.55.3 4 66789 5057 4980 0 0 0 03:30:00 Idle (Admin)
我想在陣列ID(router_name
)只含有03:30:00
的線來表示,而如果它小於6小時後,我想刪除從其餘陣列。
在我的PHP代碼是這樣的:
$bgp_routers = "/path/to/a/file/that/contains/the/router/list";
$routers_list = array_filter(explode("\n",file_get_contents($bgp_routers)),'strlen');
foreach ($routers_list as $k=>$v) {
$bgp_out[$v]=array_filter(explode('#',shell_exec("$bgp_expect $v")),'strlen');
$bgp_out[$v] = $bgp_out[$v][2];
}
foreach ($bgp_out as $k=>$v){
$bgp_out2[$k] = array_filter(explode("\n",preg_replace(array('/sh ip b s \| i Active\|Idle/'),'',$v)),'strlen');
array_pop($bgp_out2[$k]);
unset($bgp_out2[$k][0]);
}
foreach ($bgp_out2 as $k=>$v){
$count = count($v);
for ($i=1;$i<=$count;$i++) { $bgp1[$k][$i] = (preg_match('/(\s+|.*):(\s+|.*)/',$v[$i])) ? $v[$i] : ''; }
}
和輸出爲:預計
Array
(
[router_name3] => Array
(
[1] => 324.32.1.110 4 34522 0 0 0 0 0 never Idle (Admin)
[2] => 324.32.1.114 4 34522 0 0 0 0 0 never Idle (Admin)
[3] => 324.32.1.118 4 34522 0 0 0 0 0 never Idle (Admin)
)
[router_name4] => Array
(
[1] => 324.32.0.106 4 42343 0 0 0 0 0 03:01:21 Active
[2] => 324.32.2.22 4 24234 0 0 0 0 0 never Active
[3] => 324.32.13.238 4 32432 0 0 0 0 0 never Active
[4] => 12.324.218.82 4 42332 9743 9236 0 0 0 3d15h Idle (Admin)
[5] => 12.324.218.117 4 12312 8434 9214 0 0 0 3d15h Idle (Admin)
[6] => 3.86.127.121 4 12444 5057 4980 0 0 0 00:01:00 Idle (Admin)
[7] => 94.17.37.165 4 39737 4521 5015 0 0 0 3d15h Idle (Admin)
[8] => 18.21.121.73 4 14124 27364 26346 0 0 0 3d15h Idle (Admin)
)
[router_name1] => Array
(
[1] => 324.32.10.78 4 39335 13851 81070 0 0 0 1y8w Active
[2] => 324.32.11.18 4 34732 0 0 0 0 0 never Active
[3] => 324.32.12.178 4 43890 0 0 0 0 0 8:00:00 Idle (Admin)
[4] => 324.32.13.150 4 34279 0 283414 0 0 0 never Idle
)
[router_name2] => Array
(
[1] => 324.32.0.114 4 5483 1194812 416375 0 0 0 2w0d Active
[2] => 12.324.218.1 4 3234 3663159 5094548 0 0 0 1w0d Active
)
)
:
$ bgp_out:
Array
(
[Router_name3] => sh ip b s | i Active|Idle
332.11.1.110 4 12341 0 0 0 0 0 never Idle (Admin)
332.11.1.114 4 12341 0 0 0 0 0 never Idle (Admin)
332.11.1.118 4 12341 0 0 0 0 0 never Idle (Admin)
Router_name3
[Router_name4] => sh ip b s | i Active|Idle
332.11.0.106 4 423432 0 0 0 0 0 03:01:21 Active
332.11.2.22 4 42322 0 0 0 0 0 never Active
332.11.13.238 4 5243 0 0 0 0 0 never Active
2.11.218.82 4 2222 9743 9236 0 0 0 3d14h Idle (Admin)
2.11.218.117 4 23423 8434 9214 0 0 0 3d14h Idle (Admin)
190.86.127.121 4 234 5057 4980 0 0 0 00:01:00 Idle (Admin)
94.177.37.165 4 423423 4521 5015 0 0 0 3d14h Idle (Admin)
178.21.121.73 4 423432 27364 26346 0 0 0 3d14h Idle (Admin)
Router_name4
[router_name1] => sh ip b s | i Active|Idle
332.11.10.78 4 42343 13851 81070 0 0 0 1y8w Active
332.11.11.18 4 75675 0 0 0 0 0 never Active
332.11.12.178 4 76576 0 0 0 0 0 never Idle (Admin)
332.11.13.150 4 65756 0 282570 0 0 0 never 08:00:00
router_name1
[Router_name2] => sh ip b s | i Active|Idle
332.11.0.114 4 5675 1194812 416375 0 0 0 2w0d Active
2.11.218.1 4 45666 3663159 5094548 0 0 0 1w0d Active
Router_name2
)
$ bgp_out2輸出:
array (
[router_name4] =>
array(
[0] => 324.32.0.106 4 42343 0 0 0 0 0 03:01:21 Active
[1] => 3.86.127.121 4 12444 5057 4980 0 0 0 00:01:00
)
)
任何解決方案?
你已經試過了什麼? – falinsky
我已添加到問題中。 – Cosmin
因此,如果至少有一行閒置<6小時,您只想顯示該行......如果沒有,顯示所有內容? –