5

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 foo@bar.com '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?

ChaimKut
  • 2,759
  • 3
  • 38
  • 64
  • Have you tried `echo 'print "Hello World"' | ssh localhost -p 12345`? – sshine Aug 31 '15 at 10:17
  • The result (using ssh -v for verbose debugging): `root@localhost's password: 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 shell request failed on channel 0` – ChaimKut Aug 31 '15 at 10:54

1 Answers1

3

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.

Konstantin Svintsov
  • 1,607
  • 10
  • 25