1#!/usr/bin/env python 2 3 4import os 5import sys 6 7# ---------Set sys.path for pluqin execution--------------------------------------- 8# Absolute path to this plugin 9abs_path = os.path.abspath(os.path.dirname(sys.argv[0])) 10# full_path to plugins parent directory 11full_path = abs_path.split('plugins')[0] 12sys.path.append(full_path) 13# Walk path and append to sys.path 14for root, dirs, files in os.walk(full_path): 15 for found_dir in dirs: 16 sys.path.append(os.path.join(root, found_dir)) 17 18# ssh_utility is in ../lib 19from ssh_utility import SSHRemoteclient 20 21 22def ssh_execute_cmd(hostname, 23 username, 24 password, 25 command, 26 timeout=60): 27 r""" 28 Description of argument(s): 29 30 hostname Name/IP of the remote (targeting) host 31 username User on the remote host with access to FFCD files 32 password Password for user on remote host 33 command Command to run on remote host 34 timeout Time, in second, to wait for command completion 35 """ 36 ssh_remoteclient = SSHRemoteclient(hostname, 37 username, 38 password) 39 40 cmd_exit_code = 0 41 err = '' 42 response = '' 43 if ssh_remoteclient.ssh_remoteclient_login(): 44 45 """ 46 cmd_exit_code: command exit status from remote host 47 err: stderr from remote host 48 response: stdout from remote host 49 """ 50 cmd_exit_code, err, response = \ 51 ssh_remoteclient.execute_command(command, timeout) 52 53 # Close ssh session 54 if ssh_remoteclient: 55 ssh_remoteclient.ssh_remoteclient_disconnect() 56 57 return response 58