I'm running this shell script from within a php script at the command prompt.
<?php
$monitorDir = 'logs';
$script = "" .
" inotifywait -mqr --format '%w %f %e' $monitorDir | " .
" while read dir file event;" .
" do" .
" if [ \"\$event\" == \"CLOSE_WRITE,CLOSE\" ];" .
" then" .
" echo finished writing \$file; ".
" fi;" .
" done";
$proc = proc_open($script, $descriptors, $pipes);
When I run it I end up with output that looks like this:
sh: 1: [: MODIFY: unexpected operator
sh: 1: [: CLOSE_WRITE,CLOSE: unexpected operator
sh: 1: [: MODIFY: unexpected operator
sh: 1: [: OPEN: unexpected operator
sh: 1: [: MODIFY: unexpected operator
The strange thing is, when I echo out $script in the php and paste the resulting output in to the command shell it runs fine.
It looks like the problem is around if [ \"\$event\" ==.
Anyone see what I'm missing here?
Edit
Below is the exact output rendered by the php, Appologies for the formatting but I thought I'd leave it 'as is' to demonstrate what is being produced.
inotifywait -mqr --format '%w %f %e' logs | while read dir file event; do if [ "$event" == "CLOSE_WRITE,CLOSE" ]; then echo finished writing $file; fi; done
As I say, when pasted in to the console it runs fine, it just fails when opened with proc open.
proc_openand getting some errors being blind, first echo the$scriptand review it. When you're confident (strings are explained quite well in the PHP manual, otherwise ask) with the output and you've verified it's indeed the script you want to execute, bring back in theproc_open.$scriptand paste the result directly into the console it runs fine. any Ideas why it doesn't work from the php?