У меня есть bash-скрипт, который привязывает файл к строке, содержащей «CONNECT» или «DISCONNECT».Как только такая строка найдена, эта строка передается в php-скрипт.
Вот скрипт 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
<?php
while ( 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"