亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Bash 到 php 正則表達式

Bash 到 php 正則表達式

PHP
aluckdog 2021-08-28 16:17:07
我有一個 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 回答

  • 1 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號