[Twisted-Python] sending 'tail -f' command to a remote host using conch?

Hi All, A day back I install Twisted and Conch on RHEL5. I am a novice user of Twisted software. I copied an example from dev-shed website (attached herewith). This example script uses conch to talk to a ssh deamon. This script was able to capture and return the output of simple commands such as - ls, cat etc. I mean, when I run the script to execute 'ls -al' on a remote machine it does and returns the prompt. Where as, when I run the script to execute '*tail -f /path/to/mylog.txt*' I get the ouput of this command but the prompt never returns. When I press ^C (Control-C) I get the following run-time error. *Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/internet/tcp.py", line 520, in connectionLost protocol.connectionLost(reason) File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/conch/ssh/transport.py", line 166, in connectionLost self.service.serviceStopped() File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/conch/ssh/connection.py", line 59, in serviceStopped map(self.channelClosed, self.channels.values()) File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/conch/ssh/connection.py", line 580, in channelClosed log.callWithLogger(channel, channel.closed) --- <exception caught here> --- File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/python/log.py", line 84, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/python/log.py", line 69, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/python/context.py", line 59, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/python/context.py", line 37, in callWithContext return func(*args,**kw) File "shankha.py", line 56, in closed reactor.stop() File "/usr/lib/python2.4/site-packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/internet/base.py", line 526, in stop raise error.ReactorNotRunning( twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running.* *I know that 'tail -f' command is expecting "Control-C" or Break to return the prompt on remote host. But my attempt to send the ^C character is failing.. I am doing somethink like this: python sshc.py <hostname> 'tail -f mylog.txt ; \x03' What is the recommended method to adopt such cases? *Cheers!! Harsha Reddy

On 06:10 am, nharsha@gmail.com wrote:
Hi All,
A day back I install Twisted and Conch on RHEL5. I am a novice user of Twisted software. I copied an example from dev-shed website (attached herewith). This example script uses conch to talk to a ssh deamon.
This script was able to capture and return the output of simple commands such as - ls, cat etc. I mean, when I run the script to execute 'ls -al' on a remote machine it does and returns the prompt.
Where as, when I run the script to execute '*tail -f /path/to/mylog.txt*' I get the ouput of this command but the prompt never returns. When I press ^C (Control-C) I get the following run-time error. [snip] File "shankha.py", line 56, in closed reactor.stop() File "/usr/lib/python2.4/site- packages/Twisted-8.2.0-py2.4-linux-i686.egg/twisted/internet/base.py", line 526, in stop raise error.ReactorNotRunning( twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running.*
This happens because your program tries to stop the reactor twice. First, it tries to stop it when you hit ^C - the default handing of ^C is to stop the reactor. Then, your SSH connection is closed (because all connections are closed when the reactor is stopped). Your code handles this by calling reactor.stop() again.
*I know that 'tail -f' command is expecting "Control-C" or Break to return the prompt on remote host. But my attempt to send the ^C character is failing..
I am doing somethink like this:
python sshc.py <hostname> 'tail -f mylog.txt ; \x03'
What is the recommended method to adopt such cases?
You need to set up some glue. Right now, ^C is not being sent to the remote process at all. It's only being sent to your local sshc.py process. You may want to install your own SIGINT handler, or you may want to add a before shutdown trigger (or use a service's stopService method) to send ^C to the remote process. As to what the Conch API is for sending a signal to a process, I'm not sure. Jean-Paul
participants (2)
-
exarkun@twistedmatrix.com
-
Harsha