Shell file to run other shell files running jar files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell file to run other shell files running jar files
# 1  
Old 07-15-2014
Shell file to run other shell files running jar files

Hi,
I am trying to write a shell script that will go to another folder and run the script in that folder. The folder structure is kind of like this:

/MainFolder/
|-> MainShellScript.sh
|
|-> Folder1/
|-----|-> script1.sh
|-----|-> FileToRun1.jar
|
|-> Folder2/
|-----|-> script2.sh
|-----|-> FileToRun2.jar

So, trying to run MainShellScript.sh, which in turn will run the script1.sh and script2.sh, where these guys are running the jar files in their respective folders.

The code is as follows:

MainShellScript.sh:
Code:
#!/bin/bash

for d in */ ; do
    sh "$d"/script1.sh &
done

Script1.sh:
Code:
JAVA_EXE=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/bin/java
${JAVA_EXE} -Dsun.lang.ClassLoader.allowArraySyntax=true  -jar FileToRun1.jar > output.txt &

There are two problems:
1 - when I call the MainShellScript.sh, it does call the script1 and script2 successfully, but those scripts in turn cannot find the jar files. I get the following message:
Code:
Error: Unable to access jarfile FileToRun1.jar
Error: Unable to access jarfile FileToRun2.jar

2 - the script1 and script2 both are redirected to output.txt. When I call the MainShellScript.sh, it creates only one output.txt under the MainFolder/

Any advice would be greatly appreciated Smilie
Thanks!
# 2  
Old 07-15-2014
I don't use java but how about trying:-
Code:
${JAVA_EXE} -Dsun.lang.ClassLoader.allowArraySyntax=true  -jar /ABSOLUTE/PATH/TO/FileToRun1.jar > output.txt &

Also check the directory tree and file(s) have the correct permissions...
# 3  
Old 07-16-2014
thanks wisecracker....but unfortunately it seems this is not working either. The java file in turn calls a properties file, which when run from the MainShellScript.sh throws a exception "java.io.FileNotFoundException".

From I suspect, it has to do with the scope of the shell script. When calling the MainShellScript.sh, it seems like the active current directory becomes the MainFolder's directory for all the subsequent shell scripts called.
# 4  
Old 07-16-2014
Try
Code:
#!/bin/bash
P=$(pwd)
for d in */ ; do 
  cd $P/$d
  sh script?.sh &
  done
cd $P

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

How to run the files in Linux shell scipt?

I have a homework and I tried to work on this but unable to find the solution. Can someone help me how to resolve the issue. I have a package file and it contains text file as prod.ame300_000001.101414145111.A.txt. In the text file it contains pdf file... (1 Reply)
Discussion started by: pavand
1 Replies

2. Shell Programming and Scripting

Shell script to encrypt the xls file using executable jar in Linux SUSE 11.4

Dear Experts, I am an ERP consultant and would like to learn shell script. We are working on Linux SUSE 11.4 and I am very new to shell scripting. We can manually encrypt an excel file using "executable jar" through command prompt by placing the jar file & the file to be encrypted on a physical... (1 Reply)
Discussion started by: nithin226
1 Replies

3. Shell Programming and Scripting

How to get CRC check sum of files in java EAR file without extracting .jar/.war files to disk.?

unzip -v gives CRC info of each file in a zip(in my case .EAR) file. # unzip -v my-application.ear Archive: my-application.ear Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 197981 Defl:N 183708 7%... (1 Reply)
Discussion started by: kchinnam
1 Replies

4. Shell Programming and Scripting

Read files in shell script code and run a C program on those files

HI, I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this: 1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

5. Shell Programming and Scripting

Running tcl Files in C shell

hello, debashish here.Can any body tell me, how to execute tcl files in a C shell. i am working in synopsys tool for synthesis work. plz help me out.:confused::wall: $ source /packages/synopsys/setup/create_dir_setup.tcl $ source /packages/synopsys/setup/synopsys_setup.tcl i want to execute... (1 Reply)
Discussion started by: DEBASHISH DASH
1 Replies

6. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

7. Shell Programming and Scripting

Running multiple files through shell script with a variable

Ok, so this question is probably much easier than I'm making it, and thus why I've spent almost 2 hours now on this :wall:. I'm trying to use a command that reads out specific data from a file and and saves it to another file. The code is only a few lines, and here it is below: #!/bin/csh ... (4 Replies)
Discussion started by: mysterionRises
4 Replies

8. Shell Programming and Scripting

shell script to run .sql files

hi Friends, Please help me in writing shell script to run list of sql files. database is Oracle 9i, unix os is solaris Requirement is 1. sql file must take two inputs a)feed id and b)business date 2.shell script must out put .xls or .csvfile as out put without trimming any column name and... (1 Reply)
Discussion started by: balireddy_77
1 Replies

9. Shell Programming and Scripting

want to run different files under the same program using shell script

suppose have different files 1.1 2.2 3.3 4.4 5.5 All the files have to run under the same command say tr -d '\n' so how to run all the files under the same command by using shell script (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question