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?

nopcorn
  • 9,559
  • 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. – nopcorn 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. – nopcorn 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
  • 125,559
  • 25
  • 270
  • 266
  • Makes sense. I didn't know you had to modify the file descriptor to get at the STD streams. Thanks Chris. – nopcorn 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