LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-30-2007, 07:22 AM   #1
freakolowsky
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Rep: Reputation: 0
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.

Last edited by freakolowsky; 01-30-2007 at 07:24 AM.
 
Old 01-30-2007, 07:31 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,453

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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.
 
Old 01-30-2007, 07:45 AM   #3
freakolowsky
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
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??
 
Old 01-30-2007, 07:53 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,453

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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!
 
Old 01-30-2007, 08:11 AM   #5
freakolowsky
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
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.

Last edited by freakolowsky; 01-30-2007 at 08:16 AM.
 
Old 01-30-2007, 08:16 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,453

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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.
 
Old 01-30-2007, 08:22 AM   #7
freakolowsky
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
The problem is that the console is a TTY, so it's not inside X.
 
Old 01-30-2007, 01:32 PM   #8
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
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?
 
Old 01-31-2007, 04:43 AM   #9
freakolowsky
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
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 ...


so as i said without modifying a command/script/whatever i MEANT without modifying anything ... adding stuff ie. redirection is also modifying
 
Old 01-31-2007, 05:12 AM   #10
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 01-31-2007, 05:17 AM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,944
Blog Entries: 54

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

Last edited by unSpawn; 01-31-2007 at 05:34 AM.
 
Old 01-31-2007, 05:35 AM   #12
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,453

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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!
 
Old 06-01-2007, 06:54 PM   #13
dustint
LQ Newbie
 
Registered: Jun 2007
Posts: 1

Rep: Reputation: 0
Alternatively you can run your command in screen. gentoo-wiki.com/TIP_Using_screen

Handy for those extra-long compiles
 
  


Reply

Tags
bash, ssh


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regaining output from a background process the_holysmoke Linux - Newbie 4 03-11-2011 06:48 PM
How to process ping output with sed? Griffon26 Linux - General 5 08-30-2009 04:16 PM
Howto get the output of a running process using ssh? agouz Linux - Software 3 12-26-2005 12:11 PM
Problem in output to a process in perl saneax Linux - Software 2 08-31-2004 06:18 AM
Redirecting process output to shell mhelles Linux - Newbie 1 04-30-2003 09:30 AM


All times are GMT -5. The time now is 08:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration