Friday 15 March 2013

Bash script run by PHP exec() not doing redirection properly -


I have a script that takes some parameters and redirects the output of a Hurdock to another file, so that the virtual File for Host Web Server When I run the script in the command line, it performs fine and the file is created, but when I run it using PHP exec or shell_exec, it does not make the file. Everything else (resonant or trying to return output instead of redirection) moves precisely - not just creating the file and I do not get any signal that there was a problem.

Here's my code: Create_vhost.sh:

  #! Use the template to create the / bin / bash # vhost file "Create a vhost file in the sites-available" sudo /absolute/path/to/vhost_template.sh $ 1 $ 2 & gt; / Etc / nginx / sites-available / $ 2 service nginx restart   

I run the script above like this: /absolute/path/to/create_vhost.sh site_id domain .com and it works perfectly with SSH with terminal.

For reference, the vhost_template file is like this:

  #! / Bin / sh SITE_ID = $ 1 DOMAIN = $ 2 # Define the template Cat & lt; & Lt; IOF   

However, if I run it in PHP:

  return shell_exec (I "/absolute/path/to/create_vhost.sh site_id domain. Com ");   

I found the output ok, but no file has been created! And like I said, if I leave redirection, I still see the output of the template file with no problem in PHP.

I was looking for it for hours, but I'm just stumped. Any suggestions? Edit: Just thought I thought that maybe it's a matter of permission, but I tried to use soda within shell_exec () and to give www data data pods privilege Used Visual Studio Still the same problem ...

You have some important information that is Stderr So you can try to redirect the stderr output to stdout . You will be able to debug the problem.

  return shell_exec ("/ absolute / path / to / create_vhost.sh site_id domain.com 2 & gt; and 1");    

No comments:

Post a Comment