Quick Question about Linux command from Controller

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.

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 for details and updates!

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?

On Wed, Jul 23, 2008 at 8:52 AM, Joe P.
[email protected] 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. ------------------------ [email protected]

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

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).

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 :slight_smile:

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 for details and updates!