I’m thinking to write a php script to kill a particular screen when meeting criteria and the screen is require root access. I notice when you call the php script it will use apache as user. How do i set it as root? Below code does not work for me. Please help.
I use php because need to query some condition from database.
Is it possible to run query in shell script? If possible then I can set this script to root’s cron. Then should have root access to kill the screen.
Run the screen as Apache is one solution, give Apache access to the screen is another (a security disaster waiting to happen).
A better solution, might be to signal to the screen it needs to die, I’m assuming you are running a PHP script in the screen? If so, maybe get it to check a status file / flag somewhere and if it finds it, clean up and stop.
Thanks for reply. I’ve found using shell script is the best solution for me. Just schedule it as root’s cron then it will have the privilege to kill screen at my prefer time and prefer screen.
db_name='dbName'
user_name='dbUser'
password='dbPass'
result=$(mysql -u $user_name $db_name -p$password -sN -e "SELECT COUNT(id) AS num FROM tblQue WHERE status='P'")
if [ "$result" -lt 100 ];
then
echo "Close screen"
/usr/bin/screen -dr scnProcessA -X quit
fi
I’ve tried that. But apache has no access to kill root’s screen. unless you grant root access to apache but that would be a security risk as mentioned by logic_earth.
Erm… Apache would have nothing to do with it unless you were running it from the apache users cron. PHP doesn’t have to be called via the server, you can set a root cron job up i.e.
*/5 * * * * php /path/to/your/script.php
which will execute your PHP script from the command line as the root user, assuming you’ve got CLI PHP installed (which is most likely).