我想通過 SSH 輸出獲取應用程式的一些資料;
root@serve:~# eshtr --statuscheck true --trackerid 06897ea6-ed4d-43c4-bf94-ec8643628943
[ESHTR][INTERNALSERVER][StatusChecker] Status: Standby_Mode
Available status: shutdown, reset, reboot, rightmove, leftmove, rebootgps, rebootping, rebootlights, uwpring
Tracker ID: 06897ea6-ed4d-43c4-bf94-ec8643628943
正則運算式:'/(\bAvailable status: \b)(?!.*\1)/m';
preg_match_all($pattern['availableStatus'], $sshResult, $matches, PREG_SET_ORDER, 0);
if (isset($matches[0])) {
foreach ($matches[0] as $match) {
$options = explode(',' $match);
// shutdown
// reset
// reboot
// rightmove
//...
}
}
我想將它添加到options表單結構中,但是如何從 SSH 結果中獲取狀態選項?
uj5u.com熱心網友回復:
只需對 RegEx 進行一點調整,這似乎作業正常。以下還過濾結果以使用每個狀態代碼修剪多余的空格array_walk
$response='root@serve:~# eshtr --statuscheck true --trackerid 06897ea6-ed4d-43c4-bf94-ec8643628943
[ESHTR][INTERNALSERVER][StatusChecker] Status: Standby_Mode
Available status: shutdown, reset, reboot, rightmove, leftmove, rebootgps, rebootping, rebootlights, uwpring
Tracker ID: 06897ea6-ed4d-43c4-bf94-ec8643628943';
$pttn='/(Available status: )(.*)/m';
preg_match( $pttn, $response, $results );
$data=explode( ',', $results[ count( $results )-1 ] );
array_walk($data,function( &$item ){
$item=trim( $item );
});
printf('<pre>%s</pre>',print_r($data,true));
產生:
Array
(
[0] => shutdown
[1] => reset
[2] => reboot
[3] => rightmove
[4] => leftmove
[5] => rebootgps
[6] => rebootping
[7] => rebootlights
[8] => uwpring
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/485673.html
