# Quick Question about Linux command from Controller

**URL:** <https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896>\
**Category:** Rails\
**Created:** [July 23, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896 "2008-07-23T17:22:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [July 23, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896/1 "2008-07-23T17:22:38Z")

</div>

Good morning,

I am trying to execute a linux command from inside my controller. It  
works on my development machine, but does not work in production. Here  
is the code.

def get\_whois  
@the\_site = Site.find\_by\_id(params[:id])  
unless @the\_site  
flash[:error] = “Site could not be found”  
redirect\_to :action =\> :index and return  
end  
@the\_site.whois = `whois #{@site.domain}`  
@the\_site.save  
flash[:notice] = “WHOIS information captured”  
redirect\_to :action =\> :show, :id =\> @the\_site.id  
end

Does anyone know why this doesn’t work in production mode? It works  
fine in development…

Any advice is appreciated.

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [July 23, 2008, 5:44pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896/2 "2008-07-23T17:44:56Z")

</div>

Hi Joe –

On Wed, 23 Jul 2008, Joe P. wrote:

> flash[:error] = “Site could not be found”  
> redirect\_to :action =\> :index and return  
> end  
> @the\_site.whois = `whois #{@site.domain}`  
> @the\_site.save  
> flash[:notice] = “WHOIS information captured”  
> redirect\_to :action =\> :show, :id =\> @the\_site.id  
> end
> 
> Does anyone know why this doesn’t work in production mode? It works  
> fine in development…

I suspect it’s very unlikely that this is the issue but the first  
thing that popped into my head was whether it’s running as a different  
user in production, with a different path.

David

–  
Rails training from David A. Black and Ruby Power and Light:  
Intro to Ruby on Rails July 21-24 Edison, NJ

- Advancing With Rails August 18-21 Edison, NJ
- Co-taught by D.A. Black and Erik Kastner  
See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [July 23, 2008, 5:52pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896/3 "2008-07-23T17:52:49Z")

</div>

> I suspect it’s very unlikely that this is the issue but the first  
> thing that popped into my head was whether it’s running as a different  
> user in production, with a different path.
> 
> David

Hey David –

Hmm… if that was the problem, then how should I change it so it works?  
What else could be causing it to work in development, but not  
production?

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [July 23, 2008, 6:32pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896/4 "2008-07-23T18:32:38Z")

</div>

On Wed, Jul 23, 2008 at 8:52 AM, Joe P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hmm… if that was the problem, then how should I change it so it works?

I’m not David, but one obvious answer is use an absolute path, e.g.

```
@the_site.whois = `/usr/bin/whois #{@site.domain}`

```

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [July 24, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896/5 "2008-07-24T21:18:49Z")

</div>

On Wed, 23 Jul 2008, Joe P. wrote:

> @the\_site.whois = `whois #{@site.domain}`  
> @the\_site.save  
> flash[:notice] = “WHOIS information captured”  
> redirect\_to :action =\> :show, :id =\> @the\_site.id  
> end

Do you get an error? What is the error?

Does the production machine even have that command available?  
Since whois connects to external servers, do you know if that connection  
is allowed (i.e. is there a firewall or some other network filtering  
going  
in?).

Lots of variables. Need more data.

–  
A

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [July 24, 2008, 9:38pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896/6 "2008-07-24T21:38:50Z")

</div>

Man I feel dumb. I wasn’t getting any error I could see, but it became  
clear as day once I sshed onto the live server.

It turns out WHOIS wasn’t installed on the Ubuntu server.

So I just did:  
sudo apt-get install whois

I love how the weirdest problems have such simple solutions (sometimes).

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [July 24, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/quick-question-about-linux-command-from-controller/143896/7 "2008-07-24T21:43:02Z")

</div>

Hi –

On Thu, 24 Jul 2008, Joe P. wrote:

> Man I feel dumb. I wasn’t getting any error I could see, but it became  
> clear as day once I sshed onto the live server.
> 
> It turns out WHOIS wasn’t installed on the Ubuntu server.
> 
> So I just did:  
> sudo apt-get install whois
> 
> I love how the weirdest problems have such simple solutions (sometimes).

Well, I guess I was right that it wasn’t in the program’s path 🙂

David

–  
Rails training from David A. Black and Ruby Power and Light:  
Intro to Ruby on Rails July 21-24 Edison, NJ

- Advancing With Rails August 18-21 Edison, NJ
- Co-taught by D.A. Black and Erik Kastner  
See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!
