Sponsored Content
Top Forums Shell Programming and Scripting How Do I Simulate a Shell Terminal via PHP? Post 302591288 by blogmaster on Thursday 19th of January 2012 06:05:16 AM
Old 01-19-2012
Question How Do I Simulate a Shell Terminal via PHP?

----------- 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:
  1. start the shell,
  2. execute commands and print output (and errors i.e. 2>&1) to screen (STDOUT),
  3. send the shell to background when PHP disconnects to wait for more commands from the user, and
  4. 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 Smilie 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.

Last edited by blogmaster; 01-20-2012 at 02:02 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Answer Terminal Questions With Shell Script?

First off, I am using Mac OS X, with Apple Remote Desktop. I have to install several app's on teachers' laptops which are on several cd's that I have made disk images of. (DMG's) To do rollouts quicker, I have written a script to mount the disk images and running the installers inside each of... (4 Replies)
Discussion started by: The Reepr
4 Replies

2. Shell Programming and Scripting

Problem - gnome terminal shell scripting

I've a python script named rwe.py. I'm running the program in three separate terminals. If one of the executing program stops . I want to leave the terminal as it is so that i can see the error. i wrote a the below script and used cron to run it every one hour to check if the three programs are... (0 Replies)
Discussion started by: msteve2002
0 Replies

3. Shell Programming and Scripting

Set terminal width inside a shell script

Hi all, I have a shell script which uses "mailx -H" to get the subject of a email in a Linux system. However, the subject is truncated, and I think it has something to do with the terminal width because it only returns the first 80 characters of each line. I have tried "stty columns"... (7 Replies)
Discussion started by: mezzo
7 Replies

4. Shell Programming and Scripting

simulate linux shell using script

hi guys I was requested to create a script to simulate a linux shell so when the user opens linux he will get my linux menu with some options and one of those is a simulated linux shell this is my code #!/bin/ksh while do read whichcmd?"Enter Command: " $whichcmd ... (5 Replies)
Discussion started by: kopper
5 Replies

5. Shell Programming and Scripting

Freeing the terminal from busy shell script?

Hi guys, I wrote a basic inotifywait shell script on my CentOS 5.6 x86_64 test server that syncs any deleted files in a directory. /usr/bin/script #!/bin/sh inotifywait -m -e delete /home/user/test | while read file; do # log event here done The script alone works fine. However, the... (4 Replies)
Discussion started by: TECK
4 Replies

6. Programming

Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX

Writing a Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX I have over the years come across the same issue a couple of times, and it normally is that the read speed on SAN is absolutely atrocious when doing non-sequential I/O to the disks. Problem being of... (7 Replies)
Discussion started by: vrghost
7 Replies

7. Shell Programming and Scripting

executing a shell script everytime the terminal is opened

the problem statement is Write a shell script, which gets executed the moment the user opens a terminal. It should display the message "Hello your_name, welcome to 172.16.4.120 server” How to get around this? (2 Replies)
Discussion started by: arindamlive
2 Replies

8. Shell Programming and Scripting

Running shell script in Cygwin terminal

I am new to shell scripting. I tried to run a simple shell script using Cygwin terminal in Win XP env. The script I have written is as follows - #!/bin/bash a=5 ] && echo "true" || echo "false" But when I execute the script, getting some confusing error. The error I am getting are - ... (3 Replies)
Discussion started by: linux_learner
3 Replies

9. Shell Programming and Scripting

How to save and execute terminal commands in shell?

I frequently use some commands, which I want to save in some file say myregularshell.shthese are the commands I use, I tried saving and executing, but couldn't get the preview of execution, and result is also not coming if I copy same commands and paste it on terminal result is coming cd go... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

10. Shell Programming and Scripting

Kill specific terminal using shell/bash

Hello elite shell/bash specialists, I have done plenty of STFW and some RTFM, but I cannot find a clear solution to my challenge Goal: My goal is to have a script(of any language, preferably shell/bash/anything that can run things on unix), which will kill specific unix terminal windows for... (0 Replies)
Discussion started by: kamil-mech
0 Replies
ESCAPESHELLARG(3)							 1							 ESCAPESHELLARG(3)

escapeshellarg - Escape a string to be used as a shell argument

SYNOPSIS
string escapeshellarg (string $arg) DESCRIPTION
escapeshellarg(3) adds single quotes around a string and quotes/escapes any existing single quotes allowing you to pass a string directly to a shell function and having it be treated as a single safe argument. This function should be used to escape individual arguments to shell functions coming from user input. The shell functions include exec(3), system(3) and the backtick operator. On Windows, escapeshellarg(3) instead removes percent signs, replaces double quotes with spaces and adds double quotes around the string. PARAMETERS
o $arg - The argument that will be escaped. RETURN VALUES
The escaped string. EXAMPLES
Example #1 escapeshellarg(3) example <?php system('ls '.escapeshellarg($dir)); ?> SEE ALSO
escapeshellcmd(3), exec(3), popen(3), system(3), backtick operator. PHP Documentation Group ESCAPESHELLARG(3)
All times are GMT -4. The time now is 10:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy