# Extending Rake with a method rshell

**URL:** <https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403>\
**Category:** Ruby\
**Created:** [December 26, 2006, 2:36am UTC](https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403 "2006-12-26T02:36:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 26, 2006, 2:36am UTC](https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403/1 "2006-12-26T02:36:58Z")

</div>

I want to extend Rake with a method rshell, which would enable anyone  
to execute a command remotely on various UNIX boxes.

Also, if the command asks for input, then remote process’s stdin  
should be connected to current processes stdin. So, if the command  
asks for input, user can type it from current machine.

I have looked into Net::SSH, but can’t find a reliable way to  
connecting remote processes stdin to current process.

Capastrino does something like this, but not sure how?

I am trying on these lines

module Rake  
class RemoteShell  
attr\_accessor :remote\_ip,:user,:password,:remote\_shell,:channels  
def start\_ssh\_session  
@channels ||= []  
@channels \<\< Net::SSH.start(@remote\_ip,@user,@password)  
end

```
def r_shell command
  # open a channel and execute the command
  # remote process should be connected to current process stdin
end

```

end  
end

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 26, 2006, 2:50am UTC](https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403/2 "2006-12-26T02:50:58Z")

</div>

On 12/26/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Capastrino does something like this, but not sure how?
> 
> ```
> def r_shell command
> # open a channel and execute the command
> # remote process should be connected to current process stdin
> end
> 
> ```
> 
> end  
> end

I have looked into rake/contrib/sshpublisher . Yet, I wonder, how  
methods defined in classes like SshDirPublisher would MIXIN into rake.

Alternately I can simple write the method rshell,but then, I want to  
reuse ssh connection for executing other commands also.

So, without polluting Rakefile with those details, ain’t it possibly  
that all those details could be tucked away in library which extends  
Rake?

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 26, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403/3 "2006-12-26T17:33:46Z")

</div>

On 12/25/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have looked into rake/contrib/sshpublisher . Yet, I wonder, how  
> methods defined in classes like SshDirPublisher would MIXIN into rake.

In ruby, you can use mixins more-or-less anywhere

> > module A  
> > def say\_hello  
> > puts “hello world”  
> > end  
> > end  
> > =\> nil  
> > class String  
> > include A  
> > end  
> > =\> String  
> > “foo”.say\_hello  
> > hello world  
> > =\> nil

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 26, 2006, 5:39pm UTC](https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403/4 "2006-12-26T17:39:51Z")

</div>

On 12/26/06, Gregory B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > end  
> > > end  
> > > =\> nil  
> > > class String  
> > > include A  
> > > end  
> > > =\> String  
> > > “foo”.say\_hello  
> > > hello world  
> > > =\> nil

Thanks Gregory, I guess I can easily handle how to extend Rake. My  
chief problem is, right now how can i attach remote process’s stdin to  
current terminal’s input.

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 26, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403/5 "2006-12-26T18:36:00Z")

</div>

On 12/26/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks Gregory, I guess I can easily handle how to extend Rake. My  
> chief problem is, right now how can i attach remote process’s stdin to  
> current terminal’s input.

There is a chance it might be in the Net::SSH manual. I’m not sure if  
you’ve found this yet.

[http://net-ssh.rubyforge.org/](http://net-ssh.rubyforge.org/)

Also, it might be worthwhile to look at the Capistrano source if it  
has a feature similar to this.

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 27, 2006, 5:45am UTC](https://www.ruby-forum.com/t/extending-rake-with-a-method-rshell/80403/6 "2006-12-27T05:45:33Z")

</div>

Gregory B. wrote:

> Also, it might be worthwhile to look at the Capistrano source if it  
> has a feature similar to this.

Yes I have looked into Net::SSH and also have hacked with Capistrino.
