Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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?

share|improve this question
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. – user13742 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
up vote 3 down vote accepted

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.

share|improve this answer
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 6:20
@MaxMackie - Well, stdin/stdout/stderr are all merely naming abstractions of file descriptors on POSIX-compliant systems. – Chris Down Feb 19 '12 at 9:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.