[CLUE-Tech] ssh - how to pass parameters along with a script?

Jed S. Baer thag at frii.com
Fri Apr 25 14:52:09 MDT 2003


On Fri, 25 Apr 2003 13:30:06 -0700 (PDT)
Jeffery Cann <jc_cann at yahoo.com> wrote:

> Greetings.
> 
> I have a simple little shell script.  The entire thing
> is double quoted (see below) so I can pass the script
> to a remote server for its execution.
...
> $ ssh remote < script.sh   - or - 
> $ ssh remote `cat script.sh` 
> 
> The question:  how can I pass along parameters with my
> script?  I want to do something like:
> 
> $ ssh remote < script.sh "param1 param2"  
> 
> but the shell doesn't understand my intent.  I want to
> send parameters to the remote shell when it runs the
> 'script.sh'.  I'm stumped.

Well, why not wrap the whole thing inside another script, do your
substitution inside that, and send the result over ssh?

 ------ sshaaaaarrrrhhggggg.sh ---------

#!/bin/sh

ssh remote << EOD
DEPLOY_HOME=/tmp/iasdeploy/jaws
if [ ! -d $DEPLOY_HOME/$1/$2 ]
then 
	/bin/mkdir -p $DEPLOY_HOME/$1/$2
	/usr/bin/chmod 777 $DEPLOY_HOME/$1/$2
else 
	return 0
fi
EOD
# the end

Thus, invoking on your end:
$ sshaaaaarrrrhhggggg.sh param1 param2

Or, do you not have the ability (via ssh_agent, or using ssh keys) to
avoid entering the password? Oughta be someway to get that involved too.

jed
-- 
I wouldn't even think about bribing a rottweiler with a steak that
didn't weigh more than I do. -- Jason Earl



More information about the clue-tech mailing list