Redirecting SSH Output
Moderator: General Moderators
Redirecting SSH Output
Hello,
I am wondering if there is a way to redirect SSH output and have it display in something like an iframe dynamically.
Essentially, I make an SSH command and connect to a server and issue that command. I can do that no problem.
The SSH command runs a script on the server.
If I were to manually log into the server on a terminal and did the equivalent, a bunch of text would scroll by telling me what the script is doing.
It is this output that I want to pipe to an iframe so that it scrolls by as it would from a terminal.
Right now, the only way I can think of doing this is to pipe the SSH output to a file, and then constantly refresh the iframe with the file contents.
Is there some way to open a stream so that I don't have to do any file manipulation and get the benefit of "real time" content?
Thanks,
~Eric
I am wondering if there is a way to redirect SSH output and have it display in something like an iframe dynamically.
Essentially, I make an SSH command and connect to a server and issue that command. I can do that no problem.
The SSH command runs a script on the server.
If I were to manually log into the server on a terminal and did the equivalent, a bunch of text would scroll by telling me what the script is doing.
It is this output that I want to pipe to an iframe so that it scrolls by as it would from a terminal.
Right now, the only way I can think of doing this is to pipe the SSH output to a file, and then constantly refresh the iframe with the file contents.
Is there some way to open a stream so that I don't have to do any file manipulation and get the benefit of "real time" content?
Thanks,
~Eric
- maliskoleather
- Forum Contributor
- Posts: 155
- Joined: Tue May 15, 2007 2:19 am
- Contact:
i believe you are looking for passthru. just be VERY careful if you allow any user input
system() might also be interesting
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
You could offer the clients a "real" ssh client, e.g. as java applet
http://freshmeat.net/projects/thejavass ... ionapplet/
http://freshmeat.net/projects/thejavass ... ionapplet/
I thank you for the pointer to the passthru function.
It is exactly what I was looking for.
I however, have decided to deviate from my iframe design and wondered if there is a way to take the output and send it to another window, either a pop-up or another tab in their browser. I realize a pop-up would probably require a bit javascript.
I was thinking of piping the passthru output to a file, and then just calling a page that will get the contents of that file and refresh itself every second, but that seems like such a hack-ish way.
Does anyone know of a class that might exist that could help me with this?
Thanks,
~Eric
It is exactly what I was looking for.
I however, have decided to deviate from my iframe design and wondered if there is a way to take the output and send it to another window, either a pop-up or another tab in their browser. I realize a pop-up would probably require a bit javascript.
I was thinking of piping the passthru output to a file, and then just calling a page that will get the contents of that file and refresh itself every second, but that seems like such a hack-ish way.
Does anyone know of a class that might exist that could help me with this?
Thanks,
~Eric
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Why not forward the information you would give to passthru() or enough information to generate it on that end via the link?
Thats actually a better idea than my refreshing file hack.
One problem I am having is that passthru, even when I pipe the output to a file, will hold my browsers focus until the remote SSH script is run.
In the PHP passthru - Manual: http://us2.php.net/manual/en/function.passthru.php
It says you can background it by piping the output to a file.
I may have to abandon passthru, and use something that will spawn a background process.
Any ideas?
Thanks,
~Eric
One problem I am having is that passthru, even when I pipe the output to a file, will hold my browsers focus until the remote SSH script is run.
In the PHP passthru - Manual: http://us2.php.net/manual/en/function.passthru.php
It says you can background it by piping the output to a file.
I may have to abandon passthru, and use something that will spawn a background process.
Any ideas?
Thanks,
~Eric
Ok I am definitely past the passthru, wanting to grab the live output.
I simply need to background the command.
Basically the website takes in a bunch of info from a form.
It builds an SSH command.
It sends the SSH command, but the site hangs until complete.
Is there a way through PHP to background it, or do I need to use the unix & to background it?
The problem is that I am SSH'ing into a Windows server.
~Eric
I simply need to background the command.
Basically the website takes in a bunch of info from a form.
It builds an SSH command.
It sends the SSH command, but the site hangs until complete.
Is there a way through PHP to background it, or do I need to use the unix & to background it?
The problem is that I am SSH'ing into a Windows server.
~Eric
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
PHP cannot "background" a process as such, but you can construct your command to run in the background. The pcntl_..() functions may provide something too. However, your script will still need to hang if you want the output to be sent to the browser with the rest of the page. You could launch a second request for the command output by using AJAX.env wrote:Ok I am definitely past the passthru, wanting to grab the live output.
I simply need to background the command.
Basically the website takes in a bunch of info from a form.
It builds an SSH command.
It sends the SSH command, but the site hangs until complete.
Is there a way through PHP to background it, or do I need to use the unix & to background it?
The problem is that I am SSH'ing into a Windows server.
~Eric
Made in Bulgaria: http://sourceforge.net/projects/shcmd/
There are 10 types of people in this world, those who understand binary and those who don't
Thank you for all your advice.
The pcntl_() functions cannot be used for two reasons.
1. My PHP server is Windows.
2. The server I am SSHing into is also Windows
(I am a hater of Windows...but I work for a company that requires it)
I also dig all of the neat shell apps and am definitely going to look at using them to enhance my site.
For now, however, I need to user to select some settings, and then everything else needs to be non-interactive.
These scripts that I am kicking off can take up to a couple of hours to run (they are build scripts for company projects), so there is a lot of compilation time. This is why I need to simply submit the command, and refresh the page. On refresh, the page will have the form buttons disabled if it detects that a build job has been entered into the database (part of the form handling).
I am interested in the reference you made to AJAX.
Could you point me in the right direction with that?
The pcntl_() functions cannot be used for two reasons.
1. My PHP server is Windows.
2. The server I am SSHing into is also Windows
(I am a hater of Windows...but I work for a company that requires it)
I also dig all of the neat shell apps and am definitely going to look at using them to enhance my site.
For now, however, I need to user to select some settings, and then everything else needs to be non-interactive.
These scripts that I am kicking off can take up to a couple of hours to run (they are build scripts for company projects), so there is a lot of compilation time. This is why I need to simply submit the command, and refresh the page. On refresh, the page will have the form buttons disabled if it detects that a build job has been entered into the database (part of the form handling).
I am interested in the reference you made to AJAX.
Could you point me in the right direction with that?