Skip to content

Instantly share code, notes, and snippets.

@hiroyuki-sato
Created December 18, 2012 14:10
Show Gist options
  • Save hiroyuki-sato/4328270 to your computer and use it in GitHub Desktop.
Save hiroyuki-sato/4328270 to your computer and use it in GitHub Desktop.
Capistrano Executing a command as root without using sudo To avoid the error standard in must be a tty. Thank you Simone Carletti. http://www.simonecarletti.com/blog/2010/07/capistrano-executing-a-command-as-root-without-using-sudo/
#
# copy from
# http://www.simonecarletti.com/blog/2010/07/capistrano-executing-a-command-as-root-without-using-sudo/
#
def surun(command)
# To avoid the error 'standard in must be a tty'
default_run_options[:pty] = true
password = fetch(:root_password, Capistrano::CLI.password_prompt("root password: "))
run("su - -c '#{command}'") do |channel, stream, output|
channel.send_data("#{password}\n")
#
# please comment three lines if you don't need output result.
#
# if stream == :out
# puts output
# end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment