Missing argument for option: n Error

I am trying to execute the cli.sh script in another shell script passing arguments and getting the below error.
Myscript.sh

#!/bin/sh
/home/runAJobCli/cli.sh runAJobCli -n $Taskname  -t $Tasktype

I am passing the below 2 arguments and it giving error

./Myscript.sh T_SAMPLE_TEST  MTT
 
Missing argument for option: n

Does anyone has an idea what's this error.

The variable names are not being set.
So the program inside the script will be called as:

/home/runAJobCli/cli.sh runAJobCli -n -t 

The program is complaining that the -n option is missing its compulsory argument

---
Perhaps you mean to do something like this?

#!/bin/sh
Taskname=$1 Tasktype=$2
/home/runAJobCli/cli.sh runAJobCli -n "$Taskname"  -t "$Tasktype"

--
Note: Thread moved to the right forum. Please take care to open threads in the right place..

1 Like

Thanks for the reply and I updated the code and given the below arguments

Myscript.sh

#!/bin/sh
Taskname=$T_SAMPLE_TEST Tasktype=$MTT
/home/runAJobCli/cli.sh runAJobCli -n "$Taskname"  -t "$Tasktype"

./Myscript.sh

and I am getting the same error.

Missing argument for option: n

And I basically want to give the arguments outside the script. Can you help me how to do that.

That was not quite what Scrutinizer proposed: using positional parameters $1 and $2 . You'd need to call it like ./Myscript.sh $T_SAMPLE_TEST $MTT , then.
Or, export the two variables in the parent shell before calling the script, as shell variables are not inherited per se.

1 Like

Thanks it worked and I have scenario to run this from other unix server so how do I need to give the arguments over there. Below are the scripts
1.
Myscript

#!/bin/sh
Taskname=$1 Tasktype=$2
./cli.sh runAJobCli -n "$Taskname"  -t "$Tasktype"
  1. Calling the above script
    callingmyscript.sh
#!/bin/sh
ssh -t user@server "cd /home/runAJobCli/; bash" ./Myscript.sh
./callingmyscript.sh T_SAMPLE_TEST  MTT

my question is do I need to define again the arguments in the 2 script or the 1 scripts will get passed. Please give your inputs.

They aren't passed unless you pass them.

Passing them would look like ssh user@server myscript.sh "$1" "$2"

1 Like

It worked thanks a lot everyone.

---------- Post updated at 01:49 PM ---------- Previous update was at 10:47 AM ----------

Hi,

When I run the below script from other unix server in same network It ask password and need to give it manually. Is there anyway how to give the password for other server with in the network in the below script .

#!/bin/sh
ssh -t user@server "cd /home/runAJobCli/; bash" ./Myscript.sh $1 $2
1 Like

Look up the various authentication methods in man ssh , e.g. "public key authentication" will do what you request.

1 Like

Hi,

When I run the below script from other unix server in same network It ask password and need to give it manually. Is there anyway how to give the password for other server when it's in the same network in the below script .

#!/bin/sh
ssh -t user@server "cd /home/runAJobCli/; bash" ./Myscript.sh $1 $2

What will be the syntax.

Did you make any progress compared to post#7? Did you try "public key authentication"?

Hi RudiC,

Basically the script will be executed by Control-M scheduler and does this require Public Authentication key or can I keep the password in the script and what will be the syntax. Because what I heard is the Public Authentication Key is not required for the Control- M execution. Please correct me if I am wrong.

I've absolutely no clue what "Control-M" is and how it possibly works and interoperates with other applications. But, you're using ssh in your script, and, reading between your lines, some authentication IS required to fulfill your needs. "Public key auth." is one option for this amongst others.
Its setup is described in ssh 's man page and in many contributions in these forums, so it wouldn't make sense to repeat it for the n+1. time. Try it yourself and come back when you're stuck.