3

I'm trying to:

  • Launch several ssh sessions (processes) through a script (Python)
  • Communicate with the sessions by sending them commands via STDIN (even though they aren't open in my current terminal)

I've got the session spawning part down. I'm just unable to grab the process and send it stuff. I should mention this is a realm I've only recently started delving in so I'm definitely missing theory.

Explanation:

In-depth what I'm trying to do is launch ssh WITHOUT a terminal (I'm already doing this with python, so that isn't the issue) in the background. My problem arises when I actually want to communicate with the background process. How can I send data to a background process' STDIN?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
n0pe
  • 9,411
  • 13
  • 60
  • 108
  • By sending the `ssh` processes commands, do you mean arguments like i.e. `-vvv`? I guess you'll need to have each process listen to some specific socket (possibly `stdin`) to which you can direct all your messages. –  Feb 18 '12 at 22:14
  • No I mean starting an `ssh` session (logging into another server). Then sending commands to `ssh` through STDIN to the remote server. – n0pe Feb 18 '12 at 22:50
  • It may be better if you describe what exactly you are trying to accomplish, so people can suggest ways to do it. Otherwise, it just sounds like you are looking for `ssh host command-list`. – jw013 Feb 18 '12 at 23:01
  • @jw013 I added some info. Hopefully I'm communicating my question correctly. – n0pe Feb 18 '12 at 23:13

1 Answers1

5

It would be easier to use a named pipe to communicate with the processes than try to modify the FD whilst it's open. Set the named pipe as the process' standard input and write to it as required.

Chris Down
  • 122,090
  • 24
  • 265
  • 262
  • Makes sense. I didn't know you had to modify the file descriptor to get at the STD streams. Thanks Chris. – n0pe Feb 19 '12 at 06:20
  • 1
    @MaxMackie - Well, `stdin`/`stdout`/`stderr` are all merely naming abstractions of file descriptors on POSIX-compliant systems. – Chris Down Feb 19 '12 at 09:02