1

In a Rails web application program, I need to run a bash script (on the linux OS ) in the Rails environment, but I don't know how to connect my script to the Rails in order for Rails to read & run my script then send the output of script to Rails so that meet my needs.

For example, I have a server with ip:1.1.1.1 ,and write the script in the path: /usr/local/scripts/hello.sh, but whenever I run hello.sh script on this server, it prints " hello world" in the output, but my Rails applicaton is running on the server with ip:1.1.1.2. Now, I need to run hello.sh via the Rails web application on server 1.1.1.2 to send me on the webpage the output: "hello world". that is simple example to say what i need.

myscript: for example

#!/bin/bash
echo "hello world"

OS=LINUX

EDIT

describe it in the simple way:

  • I have 2 servers ip of server A:1.1.1.1 ip of server B:1.1.1.2
  • I have a scripts in (server A). Path to the script: /usr/local/script/hello.sh
  • The content on hello.sh is : #!/bin/bash echo "hello world"

I am going to call hello.sh (located on server A) using rails3 application (running on server B). In order to display the result of hello.sh (hello world) on the web page on server B.

Bohdan
  • 8,298
  • 6
  • 41
  • 51
Samira Mh
  • 11
  • 1
  • 3
  • Just to clarify `hello.sh` is stored on server A must be executed inside Rails application on server B right? – Bohdan Nov 16 '11 at 12:30

1 Answers1

3

system command ?

E.g:

system('sh http://1.1.1.1/yourscript.sh')

to get the output look here : Getting output of system() calls in Ruby

Community
  • 1
  • 1
Gaurav Shah
  • 5,223
  • 7
  • 43
  • 71
  • Thanks alot for your reply, i am realy in need, but what sections of rails must be write this command ?what folder or path? – Samira Mh Nov 16 '11 at 07:21
  • how to send the result of hello.sh to the server that running rails in order to display "hello world" in the web page – Samira Mh Nov 16 '11 at 09:11
  • call it in the controller when it is required – Gaurav Shah Nov 16 '11 at 10:27
  • this command dosn't work i get the error in "irb" system('sh http://1.1.1.1/yourscript.sh') – Samira Mh Nov 16 '11 at 11:18
  • describe it in the simple way: ------------------------- i have 2 server ip of server a:1.1.1.1 ip of server b:1.1.1.2 ---------- i have a scripts in (server a) in the blow path: /usr/local/script/hello.sh the content on hello.sh is : ------------------ #!/bin/bash echo "hello world" -------------------- i am going to call hello.sh (located on server a)using web programming via rails3 (running on server b) in order to display the result of hello.sh(hello world) on the web page on server b that is designed via rails web programming – Samira Mh Nov 16 '11 at 11:20
  • how to call in controller ? i am new in rails programming please describes in details ...thaaanks – Samira Mh Nov 16 '11 at 11:21
  • If you don't know what controller is or how to call in controller then I am afraid you must brush your basics first and then come back. – Gaurav Shah Nov 17 '11 at 01:27