[mdlug] Remote shell scripts via ssh?

Dan Pritts danno at umich.edu
Mon Feb 26 15:18:59 EST 2007


Still not elegant, could whack the remote /tmp/test.sh, 
could be subject to a race condition on the remote side, but this
basically works and doesn't require scp:

    ~@vfr800% cat /tmp/test.sh
    #!/bin/sh

    echo Foobar
    ~@vfr800% ssh wrx "cat - > /tmp/test.sh" < /tmp/test.sh
    ~@vfr800% ssh wrx "sh /tmp/test.sh"
    Foobar
    ~@vfr800% 


Or you could try this:

    ~@vfr800% ssh wrx "bash -c \"if [ -f /etc/hosts ]; then echo Foobar; fi\""

For a simple script this works but would get really ugly quickly. 
It perhaps could be used to add some security to the scenario above.



On Mon, Feb 26, 2007 at 02:00:15PM -0500, Ingles, Raymond wrote:
> 
>  I'd like to take a shell script residing on one machine, say machine A,
> and run it on machine B. Ideally, I'd like to be able to do this under the
> control of another script. And I'd like to be able to do this with SSH.
> 
>  However, ssh has the ability to run a single command line remotely, a la:
> 
>  ssh user at machine.a.org ps -ef
> 
>  ...but it won't run a local script remotely. And doing something like:
> 
>  ssh user at machine.a.org <local_script.sh
> 
>  doesn't work either. The best I've come up with is something like the
> following script:
> 
> ---------------
> #!/bin/sh
> REMHOST=$1
> REMSCRIPT=$2
> scp -q ${REMSCRIPT} ${REMHOST}:${REMSCRIPT}
> ssh -t ${REMHOST} "./${REMSCRIPT};rm ${REMSCRIPT}"
> ---------------
> 
>  But this is, well, 'inelegant'. Plus there exist systems that support
> ssh but *not* scp. Can anyone suggest a better way?
> 
>  Sincerely,
> 
>  Ray Ingles                                     (313) 227-2317
> 
>   "If your faith is disturbed by my doubt, perhaps your faith
>          wasn't all that strong to begin with." - Me
> The contents of this e-mail are intended for the named addressee only. It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or disclose it to anyone else. If you received it in error please notify us immediately and then destroy it. 
> _______________________________________________
> mdlug mailing list
> mdlug at mdlug.org
> http://mdlug.org/mailman/listinfo/mdlug

danno
--
dan pritts
danno at umich.edu
734-929-9770



More information about the mdlug mailing list