LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   want to see process output (http://www.linuxquestions.org/questions/linux-general-1/want-to-see-process-output-524033/)

freakolowsky 01-30-2007 08:22 AM

want to see process output
 
Ok, here's the situation.

I have a process running in a console on a computer. It's a simple bash script which outputs some data in stdout.

Is there a way to take-over that bash process or at least see it's output from another session, IE from a ssh console.

The solution should not include modifying the script.

colucix 01-30-2007 08:31 AM

If you refer to standard error and output, you can launch the script by redirecting them to a file, for example:
Code:

./script.sh > /some/directory/logfile 2>&1
then simply do
Code:

tail -f /some/directory/logfile
from another console.

freakolowsky 01-30-2007 08:45 AM

the "script" which is NOT in a file

while [ 1 ]; do somethin.sh; for ((i=1;i<60;i++)); do echo -n "."; done; echo ""; done

now tell me ... without modifying THAT ... how sould i redirect it??

colucix 01-30-2007 08:53 AM

Quote:

Originally Posted by freakolowsky
the "script" which is NOT in a file

What do you mean for a script which is not in a file? In which way do you run this code? Redirecting output of a command/script does not mean modify the command/script. It is simply add some words to the command line itself!

freakolowsky 01-30-2007 09:11 AM

The line of code which I posted IS what I execute in the shell, so that line is actualy my script.

So in in this context, adding redirection is actualy modifying the code.

Let me re-phrase the question ... is there a way to see the output (stdout) of a process which is run under my username under another session or is there a way to "fg" a process into my session from another session?
With session i refer to a master shell process ie. bash or sh or csh or whateversh.

colucix 01-30-2007 09:16 AM

Got it! So you want to see what happen on the console remotely, don't you? I remember this can be done on Solaris machines, as explained here, but I don't know in Linux.

freakolowsky 01-30-2007 09:22 AM

The problem is that the console is a TTY, so it's not inside X.

SciYro 01-30-2007 02:32 PM

Im confused, when i run commands like

Code:

while true; do echo hi; done
it outputs right in front of me. What exactly are you trying to do? A simple ">> somefile" at the end of the command will output what you want to another file for easy acess, but i assume you already thought of that, which again raises the question of what exactly you want to do if its so hard to modify a command, or append something to it?

freakolowsky 01-31-2007 05:43 AM

It seems to me i just can't get this question out correctly ...

Can i hijack into my session or at least see the output of a command/script/whatever which is already started.

So ... i canNOT:
- change anything in the command/script/whatever
- add redirection of output to file
- run it in a screen session
- walk on watter
- say "you're a moron" to my boss ... oh wait ... that i can ... :D


so as i said without modifying a command/script/whatever i MEANT without modifying anything ... adding stuff ie. redirection is also modifying

timmeke 01-31-2007 06:12 AM

No, I don't you can actually hijack the output of a running process and make it appear on your terminal window.
At least, not without modifying the code (ie redirection, FIFO pipes, IPC, ...).

You can still communicate with the running process ie via signals, so making it stop/suspend should work.

You can also detach the process from the terminal window it started in, but you can't make it re-attach to another terminal window afterwards. At least, not as far as I know.

See also the links to similar threads at the bottom. The first thread for instance mentions a command called "truss" (run as root) which may help you.

unSpawn 01-31-2007 06:17 AM

If it's writing somewhere, how about "strace -ewrite -p $PID"?

colucix 01-31-2007 06:35 AM

Have a look at the Text-Terminal-HOWTO, section 17.16. Probably ttysnoop is what you are looking for! Here is a link for setting it up. I wonder if it works... please post your results here! :)

dustint 06-01-2007 07:54 PM

Alternatively you can run your command in screen. gentoo-wiki.com/TIP_Using_screen

Handy for those extra-long compiles


All times are GMT -5. The time now is 11:34 PM.