def run(command, show=True): """ Runs a shell comand on the remote server """ if show: util.print_command(command) with hide("running"): return frun(command) with hide("running", "output"): return frun(command)
def sudo(command, show=True): """ Runs a command as sudo, unless the current user is root, in which case just run it """ if show: util.print_command(command) with hide("running"): if env.user == "root": return frun(command) else: return fsudo(command) else: with hide("running", "output"): if env.user == "root": return frun(command) else: return fsudo(command)
def do(*args): """ Runs command locally or remotely depending on whether a remote host has been specified and ask about continue on fail. """ with settings(warn_only=True): if env.host_string: with settings(cd(config.remote_path)): result = frun(*args, capture=False) else: result = local(*args, capture=False) if result.failed: if result.stderr: print(red(result.stderr)) if not confirm("Continue anyway?"): abort('Stopped execution per user request.')
def display_action(): action = request.query.cmd method = request.query.param try: if (action == 'spam'): if os.name == 'nt': env.host_string = 'rpiMON' env.user = '******' env.use_ssh_config = True if method == "": method = "status" with settings(warn_only=True): if os.name == 'nt': out = method + " - " + frun( 'sudo service SpamMon %s' % method) elif os.name == 'posix': out = method + " - " + flocal( 'sudo service SpamMon %s' % method, capture=True) response.content_type = 'text/plain' # # fields = ('Date', 'Process', 'Severity', 'Description') # with open(logfile, 'rb') as f: # reader = csv.DictReader(f, fieldnames=fields, delimiter='|') # out = json.dumps([row for row in reader], indent=4) # response.content_type = 'application/json' # return out elif method == "": p = subprocess.Popen([action], stdout=subprocess.PIPE) else: p = subprocess.Popen([action, method], stdout=subprocess.PIPE) response.content_type = 'text/plain' out = '' for line in p.stdout: out += line.strip() + '\r\n' return out # template('{{out}}', out=out) except Exception, e: return template('Error: %s' % e)
def run(self, cmd, test=True): """ Run a command on a remote node. @type cmd: C{str} @keyword cmd: Command to run. @type warn_only: C{bool} @keyword warn_only: If set to true, this will keep executing the command, if set to false, will halt the running of commands when an error occurs. Defaults to true. @return C{list} of [stdout, stderr, exit_status] """ with fsettings(warn_only=test): results = frun(cmd) return_values = [results, results.stderr, results.return_code] return return_values
def prepare(environ, **kwargs): '''Create all directories and put files in the right places. Depends on: prepare_expdir link_agcm_inputs prepare_workdir ''' print(fc.yellow('Preparing expdir')) frun(fmt('mkdir -p {expdir}', environ)) frun(fmt('mkdir -p {execdir}', environ)) environ['model'].prepare(environ) frun(fmt('rsync -rtL --progress {expfiles}/exp/{name}/* {expdir}', environ))