How to Connect and Run Linux commands or scripts from Windows using Python

Posted 3 years, 7 months ago
Views 350
1 min read
0 reactions

Step 1:

pip install paramiko

After the above installation, you can use the below sample script to connect Linux machine from Windows.

import paramiko
import sys

def etl_trigger(host,user,passw,cmd):
    nbytes = 4096
    hostname = host
    port = 22
    username = user
    password = passw
    command = cmd
        stdin,stdout,stderr=ssh.exec_command('ls -ltr')
        outlines = stdout.readlines()
        resp = ''.join(outlines)
        # print(resp)
        return True
    except Exception as e:
        return False

hostname = 'server name'
username = username
password = password
command = 'unix command'

if __name__ == '__main__':
    etl_trigger(hostname, username, password, command)

Please let us know if you guys face any issues.

Happy Coding !!!

0 reactions


Looking for Freelancing Jobs
Joined on April 15, 2020

Latest Videos

Wanna Post Ad?
Reach a large group of audience by posting an ad about your business here. For more details
Drop us a Message