Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripting with Twisted's manhole

Summary: Unable to automate commands to Twisted's manhole. Seeking solutions/advice.

Twisted has a great piece of functionality called manhole. It allows the user to ssh to a currently running Twisted server and inspect/interact with its internals.

I would like to do some scripting with this. Connecting to manhole simply requires

ssh localhost -p 12345

and then the user is dropped into a Python interpreter with access to the running process.

Usually with ssh one can run a command on the remote server and exit, e.g.

ssh [email protected] 'ls'

will execute 'ls' on the login directory and then the ssh connection will close.

I would like to perform something like

ssh localhost -p 12345 'print "hello, world"'

to manhole, but instead I receive (with ssh verbose):

debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: print "Hello world"
exec request failed on channel 0

Anyway I can automate operations on manhole?

like image 776
ChaimKut Avatar asked Oct 19 '22 03:10

ChaimKut


1 Answers

The reason why ssh localhost -p 12345 print 'Hello world' fails is that "print 'Hello world'" is sent as "exec" request that is supposed to execute command. Your server (manhole) does not support that (obviously).

You need to feed python interpreter standard input instead. For example:

ssh -tt localhost -p 12345 << EOS
print "Hello world"
EOS

Note -tt flag - it forces ssh to allocate tty regardless your input device is not tty. Without -tt you'll receive "shell request failed on channel" error.

like image 148
Konstantin Svintsov Avatar answered Nov 09 '22 17:11

Konstantin Svintsov