Missing argument for option: n Error


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Missing argument for option: n Error
# 1  
Old 02-06-2017
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
Code:
#!/bin/sh
/home/runAJobCli/cli.sh runAJobCli -n $Taskname  -t $Tasktype

I am passing the below 2 arguments and it giving error


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

Does anyone has an idea what's this error.

Last edited by Scrutinizer; 02-06-2017 at 11:25 PM.. Reason: code tags
# 2  
Old 02-06-2017
The variable names are not being set.
So the program inside the script will be called as:
Code:
/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?
Code:
#!/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..

Last edited by Scrutinizer; 02-06-2017 at 11:34 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-07-2017
Thanks for the reply and I updated the code and given the below arguments

Myscript.sh

Code:
#!/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.

Code:
Missing argument for option: n

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



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-07-2017 at 08:48 AM.. Reason: Added CODE tags.
# 4  
Old 02-07-2017
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.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 02-07-2017
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

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

2. Calling the above script
callingmyscript.sh
Code:
#!/bin/sh
ssh -t user@server "cd /home/runAJobCli/; bash" ./Myscript.sh

Code:
./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.



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-07-2017 at 09:24 AM.. Reason: Added CODE tags.
# 6  
Old 02-07-2017
They aren't passed unless you pass them.

Passing them would look like ssh user@server myscript.sh "$1" "$2"
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 02-07-2017
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 .

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

Moderator's Comments:
Mod Comment Seriously : Please use CODE tags as required by forum rules!

Last edited by Info_Geek; 02-14-2017 at 04:40 PM..
This User Gave Thanks to Info_Geek For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find: missing argument to `-mtime'

this find command works when using manually on the command line -- $ ls -latr file*.log -rw-r--r-- 1 oracle dba 75 Jan 4 05:00 file_2.log -rw-r--r-- 1 oracle dba 75 Jan 4 05:00 file_1.log $ $ find . ! -name -prune -type f -name "file*.log" -daystart -mtime 2 ./file_1.log ./file_2.log $... (8 Replies)
Discussion started by: wtolentino
8 Replies

2. Shell Programming and Scripting

ksh - default value for getopts option's argument

Hello everyone, I need help in understanding the default value for getopts option's argument in ksh. I've written a short test script: #!/bin/ksh usage(){ printf "Usage: -v and -m are mandatory\n\n" } while getopts ":v#m:" opt; do case $opt in v) version="$OPTARG";; ... (1 Reply)
Discussion started by: da1
1 Replies

3. Shell Programming and Scripting

passing an option as an argument!

Hi Folks I have got to the point where I can specify the arguments but how to pass an option is still mystery to me. Example: temp.csh a b c d set temp1 = $argv set temp2 = $argv set temp3 = $argv echo $temp1 a echo $temp2 b echo $temp3 c d I WANT: temp.csh a b c d -S 1 set temp1... (2 Replies)
Discussion started by: dixits
2 Replies

4. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

5. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

6. Shell Programming and Scripting

command-line line 0: Missing yes/no argument

Hi Guys When I run the below command ssh -o 'PasswordAuthentication yes' -o 'PreferredAuthentications publickey' -i $HOME/.ssh/id_dsa Server_Name I found the below error ommand-line line 0: Missing yes/no argument Kindly help me to sort out Double post, continued... (0 Replies)
Discussion started by: Pratik4891
0 Replies

7. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies

9. Solaris

ps: 65535 is an invalid non-numeric argument for -p option

I want to figure out what is the reason of error message I have in Solaris 10. Why Solaris 10 dosn't recognize 65535? ps: 65535 is an invalid non-numeric argument for -p option usage: ps 'format' is one or more of: Thank you (5 Replies)
Discussion started by: gogogo
5 Replies
Login or Register to Ask a Question