[PYTHON] Remote command that behaves like a local command

Introduction

I created it because I needed it to create a stub, so I wanted a command that behaves like a local command, but actually prints the command results remotely.

environment

OSX El Capitan

How to use

Save the source with a file name of ls. Grant execute permission with chmod + x ls. All you have to do is ls.

Implementation

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

import sys
import os
from subprocess import call

argvs = sys.argv

param_hostname = '1.2.3.4'
param_username = 'docker'
param_port = '60000'
param_command = os.path.basename(argvs[0])
param_command_param = ' '.join(argvs[1:])

cmd = '/usr/bin/ssh -l %s -p %s %s %s %s' % (
        param_username, str(param_port), param_hostname, param_command, param_command_param)

call( cmd.strip().split(' ') )

result

butada-mac:remote_exec_like_a_local butada$ ./ls -l

reference

nothing special

Recommended Posts

Remote command that behaves like a local command
Run a local script on a remote host
A general-purpose program that formats Linux command strings in python
Execute a command in Go like Python's subprocess.call (~, shell = True)
A script that displays the running CloudFormation stack like a mannequin