0

I got a python script from which I use ssh to open a connection to a different host. During this session I’m trying to run another python script, with several arguments (the script is on my machine and not on the server) but the arguments are messing it up. It links the arguments to the python interpreter rather than my script.

My code looks like this:

ssh remotehost python2 < /path/to/script —-arg1 hello —-arg2 goodbye

And the error I’m getting is unknown option per each character in the argument’s name, for example: Unknown option: —-

Unknown option:a

Unknown option:r

etc.. anyway I can pass arguments without getting this error? I tried using sys args but my arguments are sentences sometimes and it doesn’t parse it well..

Nutz
  • 79
  • 2
  • 11

1 Answers1

0

To execute Scripts on a different server use paramiko to connect and to execute commands:

    Import paramiko
    
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(host,port,user,password)
    
    stdin, stdout, stderr = client.exec_command('python2 /path/to/script hello goodbye') 

    client.close()

Full doc: http://docs.paramiko.org/en/stable/api/client.html

to run a local script on a different server use:

ssh user@machine python < script.py - arg1 arg2

see Run local python script on remote server

GDF-WebDev
  • 13
  • 6