Skip to main content

Execute commands on local machine and on remote machine via ssh, and a wrapper for paramikos scp.

shell command

Wrapper around subprocess.call with shell=True

shell(cmd)

Background Unix command running

Runs a blocking unix command and returns the result

cmd_run(cmd, pr=False, streamoutput=True, returnoutput=True, cwd=None, prefix=None)

# example
cmd_run('date "+%Y-%m-%d% %H:%M"', pr=False, streamoutput=False, returnoutput=True)

# more params
call_command(command, cmdfolder=os.getcwd(), verbose=False, streamoutput=True,\
             returnoutput=False, prefix=None, ret_and_code=False)

Parameters:

  • command: unix command

  • cmdfolder=os.getcwd() -> working folder command

  • verbose=False -> prints the command

  • streamoutput=True -> prints output to stdout (keeps buffering)

  • returnoutput=False -> return the buffered output

  • prefix=None -> string to place before streaming output

  • ret_and_code=False -> return exit code also (code, val)

Variant background unix command

Common usecase scenario, run a command and get the result, possibly print to the console using an optional filter.

# example filter:
def onlyerrors(data):
    if "ERROR" in data:
        return data

cmd_exec(cmd, cmdtoprint=None, display=True, myfilter=onlyerrors)
  • cmdtoprint: unix command

  • display: print to console

  • myfilter: function used to print

SSH: run command on remote machine

Uses ssh and key authentication to logon to a remote ssh server and execute a command there.

def remote_cmd(server, cmd, username=None, timeout=60, keypath=None):

#example
remote_cmd("localhost", "rm -Rf ~/Desktop/foobar")

Parameters:

  • server: ip or domain name of server

  • cmd: unix command to execute

  • username: username used to login

  • timeout: try time to connect to server

  • keypath: path to the public key of username

tuplebased interface:

remote_cmd_map(servercmd)
  • servercmd: tuple with ( server, cmd, username, keypath )

SSH: Secure Copy Protocol

scp_get(server, fp1, fp2, username=None, keypath=None)
scp_put(server, fp1, fp2, username=None, keypath=None)

Parameters:

  • server: ip or domain name of server

  • fp1: source filepath

  • fp2: target filepath

  • username: username used to login

  • keypath: path to the public key of username

SSH: Shell

Invoke a shell on a machine

invoke_shell(server, username, keypath)

Parameters:

  • server: ip or domain name of server

  • username: username used to login

  • keypath: path to the public key of username

Download file

Wrapper around the requests library. Downloads a file with a progress bar.

download(url, mypath):

parameters:

  • url: url to download

  • mypath: filepath where to create the downloaded file

example output:

download: http://download.thinkbroadband.com/5MB.zip
00:00:02|███████████████████████         | 3.7Mi/5.0Mi

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmdssh-54.tar.gz (9.7 kB view details)

Uploaded Source

File details

Details for the file cmdssh-54.tar.gz.

File metadata

  • Download URL: cmdssh-54.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cmdssh-54.tar.gz
Algorithm Hash digest
SHA256 2efa11c4ffa24736e2f67ee15ecae56ac416644725598bd0940066850746fa79
MD5 7ef8df5a4c3287d295c7a6206f39dcfd
BLAKE2b-256 8c30121b6f03435dcbdd216e5e8188810bc9f431a9024ac82e6b1075abdb89be

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

54 This release

1 file

53

1 file

50

1 file

49

1 file

48

1 file

47

1 file

46

1 file

45

1 file

44

1 file

43

1 file

41

1 file

40

1 file

39

1 file

38

1 file

37

1 file

36

1 file

34

1 file

33

1 file

32

1 file

31

1 file

30

1 file

29

1 file

28

1 file

27

1 file

26

1 file

25

1 file

24

1 file

23

1 file

22

1 file

21

1 file

20

1 file

19

1 file

18

1 file

16

1 file

15

1 file

14

1 file

13

1 file

12

1 file

11

1 file

10

1 file

9

1 file

8

1 file

7

1 file

6

1 file

5

1 file

4

1 file

3

1 file

1

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page