-2

From one machine, I want to SSH into another machine and run a bash script there. How to do this using Python?

I can call a local command using subprocess:

subprocess.call(myfile.sh)

I want to call myfile.sh but from another machine.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Suresh Sala
  • 425
  • 1
  • 6
  • 17

1 Answers1

0

Having seen your comment below:

import paramiko

client = paramiko.SSHClient()
#client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host_ip, username=your_username, password=your_password)
ftp = client.open_sftp()
ftp.put(myfile.sh)
stdin, stdout, stderr = client.exec_command(sh myfile) #or sh myfile.sh I think
print stdout
rabs
  • 333
  • 2
  • 6