Hey all I am trying to get a bash script to fire off when I visit my php page. I am using XAMPP that is hosting my php on my MacOS.
Here is my php code:
<?php
ob_implicit_flush(true);
ob_end_flush();
$cmd = "bash sysinfo1.sh";
$descriptorspec = array(
0 => array("pipe", "r"), //stdin pipe will read from
1 => array("pipe", "w"), //stdout pipe will write to
2 => array("pipe", "w") //stderr pipe will write to
);
$process = proc_open($cmd, $descriptorspec, $pipes, realPath('./'), array());
if (is_resource($process)) {
while ($s = fgets($pipes[1])){
echo $s;
}
}
echo ']';
?>
And this is the bash script code:
#!/bin/bash
system_profiler -json SPHardwareDataType SPSoftwareDataType SPNetworkDataType SPStorageDataType
When visiting the php page (192.168.1.15:87) it loads the page just fine but has no output on the page other than the “]”. I changed the $pipes[1] to $pipes[2] and got the error:
sysinfo1.sh: line 4: system_profiler: command not found ]
I chmod 755 the bash script as well. And the .sh file is located in the same directory as the php file. The .sh script runs just fine in terminal (./sysinfo1.sh).
What could I be missing?