Class: Taskr::Actions::Shell

Inherits:
Base
  • Object
show all
Defined in:
lib/taskr/actions.rb

Instance Attribute Summary

Attributes inherited from Base

#parameters, #task

Instance Method Summary collapse

Methods inherited from Base

#initialize, #trigger

Constructor Details

This class inherits a constructor from Taskr::Actions::Base

Instance Method Details

#executeObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/taskr/actions.rb', line 113

def execute
  if parameters.kind_of? Hash
    user = parameters['as_user']
    cmd = parameters['command']
  else
    user = nil
  end
  
  if user
    `sudo -u #{user} #{cmd}`
  else
    `#{cmd}`
  end
  
  unless $?.success?
    raise "Shell command failed (#{$?}): #{cmd}"
  end
end