I just encountered the following Problem:
I’d like to restart a script in
There will occure two problems:
- How to run commands in a screens without having to attach it
- Working with screens requires
PHPto run the commands as root
We’ll need (in the end) 3 files: A
run_shell.php on the website, a
php_shell.sh that contains the script that will be executed in the screen and a
php_root that will run the
*.sh as root.
1. Run commands in a screen
The solution I use is the following:
command="echo great functions" screen -S pyLoadInit -X stuff "$command \n"
With command is the string of the command, how one would enter it in the console. The
"\n" simulates pressing the Enter key.
So that command will print
"great functions" in the screan – if you want to execute more functions at once, you can append them by using
2. How to get execute this script as root
Since running Apache as root will cause severe security issues, there must be a less risky alternative.
Filip Roséen – refp has posted a solution on Stackoverflow that creates a C-application that will run the
*.sh file with root-rights.