Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29524 > unrolled thread

Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

Started byashish <ashish.makani@gmail.com>
First post2012-09-19 12:50 -0700
Last post2012-09-20 19:45 +0200
Articles 7 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Passing arguments to & executing, a python script on a remote machine from a python script on local machine  (using ssh ?) ashish <ashish.makani@gmail.com> - 2012-09-19 12:50 -0700
    Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) Ismael Farfán <sulfurfff@gmail.com> - 2012-09-19 15:29 -0500
      Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) Piet van Oostrum <piet@vanoostrum.org> - 2012-09-20 19:30 +0200
    Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine  (using ssh ?) Tim Roberts <timr@probo.com> - 2012-09-19 20:51 -0700
    Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine  (using ssh ?) Emile van Sebille <emile@fenx.com> - 2012-09-20 07:50 -0700
    Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) Chris Rebert <clp2@rebertia.com> - 2012-09-20 09:19 -0700
      Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) Piet van Oostrum <piet@vanoostrum.org> - 2012-09-20 19:45 +0200

#29524 — Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

Fromashish <ashish.makani@gmail.com>
Date2012-09-19 12:50 -0700
SubjectPassing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)
Message-ID<10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com>
Hi c.l.p folks

Here is my situation

1. I have two machines. Lets call them 'local' & 'remote'.
Both run ubuntu & both have python installed

2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine).

I have the following questions:

1. What's the best way to accomplish my task ?
I have researched quite a bit & pretty much everybody is using ssh.
After googling a bunch, most people are using very complex workarounds to do this sort of thing. 

I googled & found people using several libraries to accomplish ssh to remote machine & execute a command on remote machine.
paramiko ( now forked into the ssh moduke), fabric, pushy ,etc

People who have used any of these libraries, which one would you recommend, as the most apt (simple & easy to use, lightweight, best performance, etc) for my situation ?

2. I would prefer a solution, which does NOT require the installation of extra libraries on the local & remote machines.
If installing external librar

3. Has anybody been able to do this using os.system ?

I tried this
>>> import os
>>> os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")

This worked, but if the arguments i tried to pass, had spaces, i was not able to 'escape' the spaces.

Any & all explanations/links/code snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor community would be greatly appreciated.

Thanks a ton

cheers
ashish

email : 
ashish.makani
domain:gmail.com

“The only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it.” - Steve Jobs (1955 - 2011)

[toc] | [next] | [standalone]


#29526 — Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

FromIsmael Farfán <sulfurfff@gmail.com>
Date2012-09-19 15:29 -0500
SubjectRe: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)
Message-ID<mailman.940.1348086557.27098.python-list@python.org>
In reply to#29524
2012/9/19 ashish <ashish.makani@gmail.com>:
> Hi c.l.p folks
>
> Here is my situation
>
> 1. I have two machines. Lets call them 'local' & 'remote'.
> Both run ubuntu & both have python installed
>
> 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine).
>
> I have the following questions:
>
> 1. What's the best way to accomplish my task ?
> I have researched quite a bit & pretty much everybody is using ssh.
> After googling a bunch, most people are using very complex workarounds to do this sort of thing.
>
> I googled & found people using several libraries to accomplish ssh to remote machine & execute a command on remote machine.
> paramiko ( now forked into the ssh moduke), fabric, pushy ,etc
>
> People who have used any of these libraries, which one would you recommend, as the most apt (simple & easy to use, lightweight, best performance, etc) for my situation ?
>
> 2. I would prefer a solution, which does NOT require the installation of extra libraries on the local & remote machines.
> If installing external librar
>
> 3. Has anybody been able to do this using os.system ?
>
> I tried this
>>>> import os
>>>> os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")
>
> This worked, but if the arguments i tried to pass, had spaces, i was not able to 'escape' the spaces.

How about something like this:
os.system ( 'ssh remoteuser@remote python remote.py "arg 1" "arg 2" "arg 3"' )

Cheers
Ismael


>
> Any & all explanations/links/code snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor community would be greatly appreciated.
>
> Thanks a ton
>
> cheers
> ashish
>
> email :
> ashish.makani
> domain:gmail.com
>
> “The only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it.” - Steve Jobs (1955 - 2011)
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Do not let me induce you to satisfy my curiosity, from an expectation,
that I shall gratify yours. What I may judge proper to conceal, does
not concern myself alone.

[toc] | [prev] | [next] | [standalone]


#29563 — Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

FromPiet van Oostrum <piet@vanoostrum.org>
Date2012-09-20 19:30 +0200
SubjectRe: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)
Message-ID<m2vcf838l2.fsf@cochabamba.vanoostrum.org>
In reply to#29526
Ismael Farfán <sulfurfff@gmail.com> writes:

> How about something like this:
> os.system ( 'ssh remoteuser@remote python remote.py "arg 1" "arg 2" "arg 3"' )

That won't work. You need an additional level of quoting because ssh is
also a shell so it adds another level of interpretation.

The following works:

os.system('''ssh remoteuser@remote "python remote.py 'arg 1' 'arg 2' 'arg 3'"''')
-- 
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]

[toc] | [prev] | [next] | [standalone]


#29537

FromTim Roberts <timr@probo.com>
Date2012-09-19 20:51 -0700
Message-ID<6j4l58dci13pe3jkc96l33atd0tppo6pg2@4ax.com>
In reply to#29524
ashish <ashish.makani@gmail.com> wrote:
>
>Here is my situation
>
>1. I have two machines. Lets call them 'local' & 'remote'.
>Both run ubuntu & both have python installed
>
>2. I have a python script, local.py, running on 'local' which needs to pass
>arguments ( 3/4 string arguments, containing whitespaces like spaces, etc )
>to a python script, remote.py running on 'remote' (the remote machine).

You haven't provided very many details, so it's possible ssh is the
low-impact solution, but don't discard the possibility of using a TCP
socket for this.  It's easy in Python.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

[toc] | [prev] | [next] | [standalone]


#29553

FromEmile van Sebille <emile@fenx.com>
Date2012-09-20 07:50 -0700
Message-ID<mailman.959.1348152551.27098.python-list@python.org>
In reply to#29524
On 9/19/2012 12:50 PM ashish said...
> Hi c.l.p folks
>
> Here is my situation
>
> 1. I have two machines. Lets call them 'local' & 'remote'.
> Both run ubuntu & both have python installed
>
> 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine).
>
> I have the following questions:
>
> 1. What's the best way to accomplish my task ?

Check out http://rpyc.sourceforge.net/ -- It's reasonably lightweight 
and has been working well for our similar situation.

Emile

[toc] | [prev] | [next] | [standalone]


#29557 — Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

FromChris Rebert <clp2@rebertia.com>
Date2012-09-20 09:19 -0700
SubjectRe: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)
Message-ID<mailman.963.1348157960.27098.python-list@python.org>
In reply to#29524
On Wed, Sep 19, 2012 at 12:50 PM, ashish <ashish.makani@gmail.com> wrote:
<snip>
> 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine).
<snip>
> 3. Has anybody been able to do this using os.system ?
>
> I tried this
>>>> import os
>>>> os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")
>
> This worked, but if the arguments i tried to pass, had spaces, i was not able to 'escape' the spaces.

Use the `subprocess` module instead (with shell=False). You then won't
need to worry about escaping.
http://docs.python.org/library/subprocess.html

Cheers,
Chris

[toc] | [prev] | [next] | [standalone]


#29564 — Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

FromPiet van Oostrum <piet@vanoostrum.org>
Date2012-09-20 19:45 +0200
SubjectRe: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)
Message-ID<m2r4pw37wk.fsf@cochabamba.vanoostrum.org>
In reply to#29557
Chris Rebert <clp2@rebertia.com> writes:

> Use the `subprocess` module instead (with shell=False). You then won't
> need to worry about escaping.
> http://docs.python.org/library/subprocess.html

You will still need to worry about escaping because on the remote end
you invoke ssh which is a shell. The obvious call:

subprocess.call(["ssh", "remoteuser@remote", "python", "remote.py", "arg
1", "arg 2", "arg 3"])

won't work because ssh will break up the "arg n" strings. You need to
use  "'arg n'" or put the whole python command in a string like:

"python TEST/testargs.py 'arg 1' 'arg 2' 'arg 3'"
-- 
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web