0

I am trying to run the shell script in the remote host , with this i also want to pass some arguments. my local host shell scripts is below

pwd
echo $0
echo $1
echo $2
echo thanku everyone!!

To run this script am using the command

ssh user@server 'ksh' < ./code

I want to pass arguments with this command. please clarify me in this..

Thanks in advance.

2
  • Would it be possible to store the script on the remote server? Commented Jan 8, 2014 at 12:27
  • I am not storing. just running the shell script from local to remote host. Commented Jan 8, 2014 at 12:53

1 Answer 1

1

You can't pass parameters because you are starting ksh and using ./code as it's standard input.

But you can set an environment variable and then use it as command line, watch!

ichramm@wilderkrieger:~$ cat code
function run() {
    echo $1;
    echo $2;
}

run $COMMAND_LINE

ichramm@wilderkrieger:~$ ssh localhost 'COMMAND_LINE="hello world" ksh' < ./code
hello
world
Sign up to request clarification or add additional context in comments.

3 Comments

No its not working. ssh user@host 'COMMAND_LINE="hello world" ksh' < ./thur1 I used like this and my code is function run(){ echo $1; echo $2; } run $COMMAND_LINE While running this code in host machine. its showing the following error syntax error : '(' unexpected. please clarify me in this.. thanks..
-> please clarify me for the above comment.
That's because my run() is a bash function, while you need a ksh function Just remove the parenthesis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.