我有一個 bash 腳本,它為包含“CONNECT”或“DISCONNECT”的字符串拖尾文件。一旦找到這樣的字符串,該字符串就會通過管道傳輸到 php sript。這是 bash 腳本:tail -f -n 1 /var/log/connections | grep -P -0 --line-buffered "\bCONNECTED\b|\bDISCONNECTED\b" | php -f $SCRIPT_DIR/connections.php這是php腳本:#!/usr/bin/php<?phpwhile ( false !== ( $connection_status = fgets ( STDIN ) ) ){ $get_status = preg_match ( "/\bCONNECTED\b|\bDISCONNECTED\b/", @$connection_status, $status_match ) ; foreach ( $status_match as $status ) { switch ( $status ) { case "CONNECTED": //If the string that got passed to this script (from the BASH script) contains CONNECTED { print ( "we are connected\r\n" ) ; } case "DISCONNECTED": //If the string that got passed to this script (from the BASH script) contains DISCONNECTED { print ( "we are disconnected\r\n" ) ; } } }}?>DISCONNECT按預期工作,但使用CONNECT,它會同時返回"we are connected"和"we are disconnected"
- 1 回答
- 0 關注
- 153 瀏覽
添加回答
舉報
0/150
提交
取消