Link to home
Start Free TrialLog in
Avatar of Rajat Sehgal
Rajat SehgalFlag for India

asked on

How to run a script using passing arguments

Hi Experts,

I,ve a cmd to viewing my application running status in Linux, this is a manual process, i need to run same process using script file ?

Please Suggest.
Proc.jpg
Avatar of arnold
arnold
Flag of United States of America image

In bash check
./script.sh argument1 argument2
$0.                  $1.             $2

The $@ is the list,  $# will return number of elements....
Avatar of Rajat Sehgal

ASKER

cat script.sh
 
#!/bin/bash
OmBabble dd_tplantc
0 1 subscribe 63001 1 abc_od

Output:-
ACE8:/home/aa=>./script.sh
>

The first line only execute...
Avatar of noci
noci

0 is not a command if you need to pass input to the OmBabble... try:

echo 0 1 subscribe 63001 1 abc_od | OmBabble dd_tplantc

or
#!/bin/bash
OmBabble dd_tplantc <<EOI
0 1 subscribe 63001 1 abc_od
EOI

Open in new window


or save as script.sh
#!/bin/bash
echo $* | OmBabble dd_tplantc 

Open in new window

and run
bash ./script.sh  0 1 subscribe 63001 1 abc_od
unable to execute in both case

cat script.sh
#!/bin/bash
OmBabble dd_tplantc <<EOI
0 1 subscribe 63001 1 abc_od
EOI

Output:-
ACE8:/home/aa=>./script.sh
>>
>>
< 32766 0 32767 1 subscribe
>>>memory map not enabled.

cat script.sh
#!/bin/bash
echo $* | OmBabble dd_tplantc

Output:-
ACE8:/home/aa=>bash ./script.sh  0 1 subscribe 63001 1 abc_od
>
>>
< 32766 0 32767 1 subscribe
>>memory map not enabled.
I do not really understand what it is you are trying to do.

Are you trying to use
./script.sh argument1 argument2

That will then use $1 and $2 passed to OmBabble?

You should always test whether the number of arguments passed $# meets your need, exit with an error if it does not.
Can you post the help screen of OmBabble please?
Presuming something like
OmBabble --help
OmBabble -h

Is this an OpenManage cli command?
Then appearantly that "input"in not  to be typed to the program...using a keyboard.
Please explain what you want to get accomplished, and HOW OmBabble needs it's input...
No way to guess, as the OmBabble script/executable is unique to your runtime environment.

As @arnold suggested, the likely problem is with your input to this script.

Post the output of this command executed on the command line...

# First version
echo "0 1 subscribe 63001 1 abc_od" | OmBabble dd_tplantc

# Second version
OmBabble dd_tplantc "0 1 subscribe 63001 1 abc_od"

# Third version
OmBabble dd_tplantc 0 1 subscribe 63001 1 abc_od

Open in new window


This will tell you if you're passing OmBabble the correct arguments.

Said another way, if OmBabble dies running interactive, running in a bash script will never fix this problem.
# First version Output:-
ACE8:/home/aa=>echo "0 1 subscribe 63001 1 abc_od" | OmBabble dd_tplantc
>
>>>memory map not enabled.
ACE8:/home/aa=>

# Second version Output:-
ACE8:/home/aa=>OmBabble dd_tplantc "0 1 subscribe 63001 1 abc_od"
babble
[-protocol tcp|ssl|http|raw|ssl_raw|udp|udp_raw|udp_broadcast|udp_raw_broadcast|udp_multicast|udp_multicast_raw
[-lang mnm|fix|none
[-local_lang mnm|fix|none
[-remote_lang mnm|fix|none
[-proxy proxy_addr]
[-verify]
[-scatter]
[-noauth]
[-daemon]
[-server]
[-dc1 | -dc2 | -hc | -ec]
[-noparse]
[-noprint]
[-terse]
[-hex]
[-replace_char char]
[-english]
[-dont_add_lang]
[-load_fields <definitions_file>]
[-interest_fields '<fid>+'
[-lit]
[-timestamp]
[-name name]
[-put file]
[-put_raw file]
[-spit file]
[-spit_raw file]
[-spit_count count]
[-spit_freq freq]
[-append file]
socket
ACE8:/home/aa=>

# Third version Output:-
ACE8:/home/aa=>OmBabble dd_tplantc 0 1 subscribe 63001 1 abc_od
babble
[-protocol tcp|ssl|http|raw|ssl_raw|udp|udp_raw|udp_broadcast|udp_raw_broadcast|udp_multicast|udp_multicast_raw
[-lang mnm|fix|none
[-local_lang mnm|fix|none
[-remote_lang mnm|fix|none
[-proxy proxy_addr]
[-verify]
[-scatter]
[-noauth]
[-daemon]
[-server]
[-dc1 | -dc2 | -hc | -ec]
[-noparse]
[-noprint]
[-terse]
[-hex]
[-replace_char char]
[-english]
[-dont_add_lang]
[-load_fields <definitions_file>]
[-interest_fields '<fid>+'
[-lit]
[-timestamp]
[-name name]
[-put file]
[-put_raw file]
[-spit file]
[-spit_raw file]
[-spit_count count]
[-spit_freq freq]
[-append file]
socket
ACE8:/home/aa=>
So it needs them on the command line and it need specific data....
Please explain what these values are
Paramter        Meaning
dd_tplantc .:
0. . . . . . . . . .:
1. . . . . . . . . .:
subscribe . .:
63001 . . . . .:
1. . . . . . . . . .:
abc_od. . . . .:

Then possibly the right option can be added...
this script is supposed to start a service?
are you trying to create a start/stop script that will be manged when the system starts, and then when the system shutsoff?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.