Skip to content
This repository has been archived by the owner on Aug 26, 2019. It is now read-only.

Handbook: Bash

Sergey Smagin edited this page Nov 22, 2015 · 4 revisions

Launch a bash command (yeah, it's still going to be necessary for a while) from a box:

box.bash "git commit -m 'changes'"

true/false will be returned, but if the bash command returns nonzero, an exception is raised with stderr.

begin box.bash "git commit -m 'changes'" 

rescue Rush::BashFailed => e
  puts "Failed to commit, reason: #{e.message}"
end

Another way to run executables:

 λ  home.ruby '-e "puts 2 + 2"'
4
   = true

Box is not necessary:

 λ  ruby '-e "puts 2 + 2"'
4
   = true

To get output of a command, use .output_of method:

 λ  home.output_of :ls, '-lah'
# less with result will be opened, result is string with output

Execute from a dir instead of a box in order to set that dir as the current directory before executing:

box['/var/www/myapp/'].bash 'mongrel_rails start'

Pass in a hash of variables to set the environment:

box['/var/www/myapp/'].bash 'mongrel_rails start', :env => { :RAILS_ENV => 'production' }

The :user parameter will use sudo capability, if you're root or a sudoer:

box.bash '/etc/init.d/nginx reload', :user => 'root'

Previous: Processes - Next: Library

source: https://web.archive.org/web/http://rush.heroku.com/handbook/bash

Clone this wiki locally