Run a linux script from a PHP file!
I know this should frikkin work but it's been pissing me off all night and I can't figure it out. I'm using shell_exec('/media/<....>/mine/script.sh'); and IT WILL NOT RUN RIGHT!!!
If I echo that command and put a return in the script, it outputs that return line. There seems to be NO errors running anything. WFT is the problem?? I've chmod'd 777 to the file, tried changing the file owner to root and nobody and NOTHING WORKS!!!! Can anyone explain why?
Latest Apache/PHP5, Ubuntu Linux
BTW the script is 3 lines really and it runs fine in a terminal on the server.
import -window root /media/disk/apache2dir/mine/screenshot.png
echo This should have ****ing worked!!
exit
Re: Run a linux script from a PHP file!
I'm sorry but your question confuses me.
What do you expect to happen?
Re: Run a linux script from a PHP file!
It should run a script (screenshot.sh) and that script will take a screenshot and save it to /media/disk/apache2dir/mine/screenshot.png, then my script will redirect to that screenshot png. The idea of the whole thing is to be able to see a screenshot on my server from anywhere I want.
EDIT
OK, I've also determined that changing the owner does nothing. Also, CRON cannot run the job either. It seems ONLY to run when used at the command line. Any ideas anyone?
Re: Run a linux script from a PHP file!
When you run it from command prompt, are you using sudo, or the command prompt is root's?
I only know a little about Linux, but it's the only thing I can think of.
Re: Run a linux script from a PHP file!
no sudo. But it does work with sudo.
Re: Run a linux script from a PHP file!
OK FYI it turns out that Cron and PHP do not by default have access to the X server in linux. To make my script (below) work with Cron, you must include a path to the DISPLAY environment variable. I think the reason that doesn't solve the PHP problem is that PHP has some issues with security when it comes to linux. I'm not quite sure how to address them.
Does anyone know?
Code:
#!/bin/bash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DISPLAY=:0
export DISPLAY;
HOME=/home/browner87
export HOME;
/usr/bin/import -display :0.0 -window root -silent /media/disk/thepath/screenshot.png