passing command arguments from a file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers passing command arguments from a file?
# 1  
Old 05-08-2012
passing command arguments from a file?

Hi

Im trying to run zip shell command from an Oracle job, but this has limitations.
This should take a few of explanaition,..
Oracle allows me to execute a command and then I can set up a fixed number of arguments. Ex: (summarizing in something like..):
JOB DEFINITION
job_name: test
job_action: /usr/bin/zip
job_arguments: 4

and then:
JOB test ARGUMENTS
ARGUMENT 1: -j
ARGUMENT 2: foo.zip
ARGUMENT 3: foo01
ARGUMENT 4: foo02
Then oracle execute "zip -j foo.zip foo01 foo02"
But the problem comes when I need an indetermined number of arguments, and cannot use spaces in arguments definitions.
So I was wondering in using something like
JOB DEFINITION
job_name: test
job_action: /bin/sh
job_arguments: 2

and then:
JOB test ARGUMENTS
ARGUMENT 1: -c
ARGUMENT 2: "/usr/bin/zip -j foo.zip foo01 foo02 andwhateverstringiwanttoconcattothis"
This *should* work, but, somehow, not Smilie .

Then I've been wondering if I can write the arguments in a plain text file and then pass arguments from that file.
It must be something like..

$ cat filename-with-args-inside
-j foo.zip foo01 foo02

$ /usr/bin/zip [SHELLOPERATORORWHATEVER] filename-with-args-inside
Is this possible?
How it should be?

I have a lazy remember from my student past that in bash that you could do this with '<<<', like:

$ /usr/bin/zip <<<filename-with-args-inside
..But it doesnt work


Any idea?

Regards

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 05-08-2012 at 01:05 PM..
# 2  
Old 05-08-2012
Can't you put whole command into file and execute it as script? For example:
Code:
JOB DEFINITION
job_name: test
job_action: /bin/sh
job_arguments: 1

and then:
JOB test ARGUMENTS
ARGUMENT 1: "/path/to/script.sh"

script.sh:
Code:
#!/bin/sh
/usr/bin/zip -j foo.zip foo01 foo02 andwhateverstringiwanttoconcattothis

# 3  
Old 05-08-2012
Yes, can do that.
Evenmore, the meaning of the capacity in execute shell commands from Oracle is intended to exec scripts, and thats why it's so poorly when you want to do complex shell instructions.

But the thing is that we want to avoid the use of shell scripts. We want to isolate the whole operation from external scripts or programs.


I had the idea of making the shell script from oracle in run time and then launch it, but the gap here is that we cant change file permissions from oracle.

Regards.
# 4  
Old 05-08-2012
You can still do that, because you don't need to set a file executable to run it.

Just
Code:
/bin/sh /path/to/script.sh

For the sh -c problem, try removing the quotes from your second string perhaps? I wonder if oracle is presenting the quotes to the shell literally.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 05-09-2012
Quote:
Originally Posted by Corona688
For the sh -c problem, try removing the quotes from your second string perhaps? I wonder if oracle is presenting the quotes to the shell literally.
... OK. This is how it works.
Smilie
It was easier than I thought.
Thanks Corona688 =]
This User Gave Thanks to vegatripy For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing Arguments to shell script from file is not working as expected.

Hi All, I have below simple shell script in cloudera quick start vm cenos 6 which copy file from source to destination. # file_copy.sh source_dir = ${source_dir} target = ${target_dir} cp source_dir target and my parameter file is like below #parameter_file.txt source_dir =... (4 Replies)
Discussion started by: Narasimhasss
4 Replies

2. Shell Programming and Scripting

How to avoid "Too many arguments" error, when passing a long String literal as input to a command?

Hi, I am using awk here. Inside an awk script, I have a variable which contains a very long XML data in string format (500kb). I want to pass this data (as argument) to curl command using system function. But getting Too many arguments error due to length of string data(payloadBlock). I... (4 Replies)
Discussion started by: cool.aquarian
4 Replies

3. Programming

Passing arguments from command line to switch case statement in C

Hi Am pretty new to C.. Am trying to pass the arguments from command line and use them in switch case statement.. i have tried the following #include <stdlib.h> main(int argc, char* argv) { int num=0; if ( argc == 2 ) num = argv; printf("%d is the num value",num); switch ( num ) ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. Shell Programming and Scripting

Passing arguments from a bash shell script to a command

I'm pretty new to bash scripting and I've found myself writing things like this (and the same with even more nesting): if $CATEGORIES; then if $LABEL_SLOTS; then $pyth "$wd/texify_grammar.py" "$input" "$texfile" "--label-slots" "--categories" "$CATEGORY_LIST" ... (9 Replies)
Discussion started by: burbly
9 Replies

5. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

6. Shell Programming and Scripting

passing arguments to unix command or script inside tclsh

hi everobody kindly consider the following in tclsh I understand that we can do the following %exec UnixCmd arg1 arg2 but if I assinged the arguments to a list insde tclsh how can I use them back i.e %set ArgList %exec UnixCmd %exec Unixcmd $list %exec all the... (1 Reply)
Discussion started by: Blue_shadow
1 Replies

7. Shell Programming and Scripting

passing arguments in remote ssh command?

i have a bash script on serverA, when i run the script on the server, it runs fine. the way to run the script is like this ./script "option1" Now i am trying to call it from local laptop using ssh command, my command is as the following ssh serverA ~/script "option1" and i got error... (7 Replies)
Discussion started by: fedora
7 Replies

8. Shell Programming and Scripting

Passing Arguments-Help

Hi, I have a script which adds the user credentials to an ldap server. Im passing the variables as below.. /path/my_script $uname $pwd $environ ${deposit} If i enter some special characters like ';' in $pwd, script returns an error which is set to display if the user enters... (5 Replies)
Discussion started by: Tuxidow
5 Replies

9. Shell Programming and Scripting

passing in arguments into a file using a loop

Hi, so Im a bit new to shell scripting and want to do the following but not sure how. Basically I have a file named "output" which contains misc text but inside the file I want to set up variables like $1 or some symbol. Anyways, in another file called "list" I have a list of items that I want to... (11 Replies)
Discussion started by: eltinator
11 Replies

10. Solaris

Passing arguments to a shell script from file while scheduling in cron

Hi, I have a shell script Scp_1.sh for which I have to pass 2 arguments to run. I have another script Scp_2.sh which in turns calls script Scp_1.sh inside. How do I make Scp_1.sh script to read arguments automatically from a file, while running Scp_2.sh? -- Weblogic Support (4 Replies)
Discussion started by: weblogicsupport
4 Replies
Login or Register to Ask a Question