----------- Summary -----------
I need a command/set of commands that can help me simulate a shell terminal via a PHP web page using commandline functions. How can I combine the power of nohup and a while loop to:
- start the shell,
- execute commands and print output (and errors i.e. 2>&1) to screen (STDOUT),
- send the shell to background when PHP disconnects to wait for more commands from the user, and
- killing the process after the exit command is issued or a certain period, say 5 mins has elapsed with no response?
Is there an easier or better way (SSH being out of the question)?
----------- The Full Story -----------
What I Need To Accomplish
I have a bash script (outsourced) that’s located outside of the web root. I need to access it (and the shell) interactively via HTTPS using PHP’s shell_exec() function. This is to support a big chunk of my clients who use my app on shared hosts and have no SSH access.
Not ideal, I know, but I can’t think of any other option. To mitigate the security risks I’m making this page accessible only to “Super Administrators” (who already have FTP access anyway). I’m also escaping the commands and arguments with escapeshellcmd() and escapeshellarg().
Problem Areas
- The shell script sometimes takes input from the Super Admin (via a web page), processes it, returns results so far and asks for confirmation to complete the process.
I thought I might be able to accomplish this by using combining nohup and a while loop but I can’t figure out the exact commands to do so. I just recently bought a couple of books on bash and shell scripting but I need an answer fast so I’m turning to you, the expert Help please…
- The shell script sometimes needs to make backups before it can finish the process. Via SSH, it’s doing this flawlessly but through shell_exec() it’s failing to create the backup directory.
This is most likely a permissions issue. If so how do I solve it without root access since this will be running on shared hosts?
I have searched Google and this forum for two days. I have gotten some great pointers and tried a few “PHP Terminal Emulators” out there but they are not interactive. They are doing directory traversing via PHP itself and can’t handle confirmation dialogs like “Are you sure you want to continue?”, which requires y/n to be passed back.