I have this PHP program in /var/www folder to run a shell script and load the HTML file created by that shell script. If I run the shell script manually from command line then it works like charm but when run via PHP program from browser then it only creates an empty file.
PHP CODE
$a = './script.sh '.$foo.' '.$bar;
$b = shell_exec($a);
include '/var/tmp/reports/r.html';
SHELL SCRIPT
cat file.ext | awk <something with $foo and $bar> | command > /var/tmp/reports/r.html
(Edit ^ "file.ext" is actually a .log file. It iss located in /var/log/.. And "command" is an other program that creates an .html file from that log file)
Permissions of my files are :
-rw-r--r-- 1 abc www-data 848 Feb 13 10:43 php.php
-rwxr-xr-x 1 ubuntu www-data 230 Feb 13 10:51 script.sh*
And /var/tmp/reports/r.html doesn't exist before execution of PHP. After execution of script directly via command line it creates r.html file like :
-rw-rw-r-- 1 ubuntu ubuntu 121884 Feb 13 11:42 r.html
But when script is executed via PHP from browser it creates an empty file like this
-rw-r--r-- 1 www-data www-data 0 Feb 13 11:43 r.html
Edit1 : On @lurker's suggestio I tried changing script.sh to
#!/bin/sh
cat file.log | awk '{if(substr($5,2)>="'$1'" && substr($5,2)<="'$2'")print $0}' | awk 'gsub(",", "", $1);' | /usr/bin/command > /var/tmp/reports/r.html
It also generated an empty file only.
Edit2 : I changed the script to ->
#!/bin/bash
sudo echo "sdfsf" > /var/tmp/reports/r.html
Even it wont work.