I want to login to different host and get want to execute the below python script

isi storagepool list -v |
awk ' /Requested Protection:/ { parity=substr($NF,length($NF)-1,1) }
    /Nodes:/ { nodes=$NF }
    /HDD Total/ { hdd_total=$NF }
    /HDD Used/ { hdd_used=$NF }
    END {
        print "parity =" parity
        print "NodeNumber =" nodes
        print "Total = " total " TB"
        print "Effective Total volume = " total*0.8 " TB"
        print "USED =" used                          
        print "Effective used=" used*multiplier*0.8 " TB" 
        print "Available volume=" (hdd_total-hdd_used)/nodes*multiplier*0.8 " TB" }'

in the below tunnel script instead of isi storagepool list command, we want to run the above command. we are not looking for exec_command the python.py script, because we can't create any file on storage host.

import paramiko
from sshtunnel import SSHTunnelForwarder

with SSHTunnelForwarder(
    ('jump_host_ip', 222),
  #  ssh_private_key_password="user_pass",
    remote_bind_address=("host_ip", 22),
    local_bind_address=('', 10022)
) as tunnel:
    client = paramiko.SSHClient()
#   client.load_system_host_keys()
    client.connect(hostname='', username='user.name, password='user_pass', port=10022)
#   client.connect('', 10022)
    # do some operations with client session
    stdin, stdout, stderr = client.exec_command('sshpass -p  ******* ssh root@Storage_host_ip "isi storagepool list"')
    print stdout.readlines()
    print stderr.readlines()

  • What is the actual question? – schaiba Apr 21 '17 at 7:14
  • I want to create a tunnel to get into the jumphost and then again run a ssh to a server and then run the awk command which gives the output – Shanker Apr 21 '17 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.