为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 145 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信