Help with writing a script to run java commands in sequence in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with writing a script to run java commands in sequence in UNIX
# 1  
Old 02-11-2015
Help with writing a script to run java commands in sequence in UNIX

Hi,

Brand new to these forums, and I hope that someone can help me out.

I'm trying to run the following command in UNIX
Code:
java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my.bam --outputRoot /my/path/SampleFiles/Sample_

It executes the SplitSamFile from GATK, but I want to run 3 additional commands, in a sequence. I can get them to run simultaneously but not in sequence, as I'm not able to pause the jobs (using ctrl + z) and put them in the background.

I've tried the following in my UNIX bash system (example with just two commands):
Code:
java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my1.bam --outputRoot /my/path/SampleFiles/Sample_ &; java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my2.bam --outputRoot /my/path/SampleFiles/Sample_ &

but this gives me the following error:

Code:
-bash: syntax error near unexpected token `;'

I've tried to consider doing a SH script, but can't figure out how to make the commands come in sequence rather than all starting at the same time.

Hope someone can help me out.

Last edited by Wixaros; 02-11-2015 at 11:53 AM..
# 2  
Old 02-11-2015
If you mean in sequence you don't need the ampersand. It's not clear what your intention is given the use of "in sequence" . The ampersand would when used correctly would run the command in a subshell.
Code:
<command> ; <command> ; <command>

# 3  
Old 02-11-2015
Do you want to run all three in sequence, but all in the background?

If so, this syntax might help you.
Code:
( cmd1 ; cmd2 ; cmd3 ) &

You could also write it like this if it makes it clearer in your script:-
Code:
(
 cmd1
 cmd2
 cmd3
) &


Sorry if I've missed the point. Your query was a little vague.



Robin

Last edited by rbatte1; 02-11-2015 at 01:15 PM.. Reason: Another coding option.
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 02-11-2015
Quote:
Originally Posted by rbatte1
Do you want to run all three in sequence, but all in the background?

If so, this syntax might help you.
Code:
( cmd1 ; cmd2 ; cmd3 ) &

You could also write it like this if it makes it clearer in your script:-
Code:
(
 cmd1
 cmd2
 cmd3
) &


Sorry if I've missed the point. Your query was a little vague.



Robin
Thank you very much! This was just the solution I was looking for, sorry fvor being a bit vague.

Completely forgot about that way of using parentheses..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Using basic UNIX commands to make/compile JAVA files

Hello! This is my first post, and I just learned what UNIX was this week. For a JAVA programming class I am taking, I must be able to create a directory in UNIX, use the nano command to create a JAVA program, compile it, and then run it on the command prompt using the java command. For some... (5 Replies)
Discussion started by: UNdvoItX
5 Replies

2. UNIX for Dummies Questions & Answers

How to compile and run java in UNIX?

Hi Im using MobaXterm Unix on my windows XP.I want to compile java in unix.I have installed java to the following path C:\Program Files\Java\jdk1.7.0_09\bin In order to compile the java prog im typing the following command after entering into the bin directory: C:\Program... (2 Replies)
Discussion started by: ak3141
2 Replies

3. Programming

Run Unix commands from Java

Greeings all Im trying to excute a command from Java and direct the output to the main output screen or to another file .... can you please help with this ? can I use filewriter for this ? Here is my code.... import java.io.BufferedReader; import java.io.File; import java.io.FileWriter;... (3 Replies)
Discussion started by: yahyaaa
3 Replies

4. Homework & Coursework Questions

Hampton Univ. help with writing commands in unix

I am trying to prompt the user using tput command to read the information ( 5 last names, first names and grades) from the keyboard. Save the data in a file called student.txt. Sort the file by last name and display it on the screen My pseudocode is as follow: Pseudocode: Initialize your... (1 Reply)
Discussion started by: jestaton
1 Replies

5. Shell Programming and Scripting

writing a shell script of commands

Can anyone help me out in visualizing on what is the logic behind simple unix commands. For Eg: ls command lists files and directories, how it displays I need to know the source code for commands like this. (1 Reply)
Discussion started by: rahul_11d
1 Replies

6. UNIX for Advanced & Expert Users

How to execute multiple unix commands in one session from java

Hi, Iam trying to code in java and wanted to run the commands in the Unix remote servers. I have the following code to run multiple GREP commands in a single session. But when i execute this, the first command executes successfully, whereas from the next line it says "Exception Occured... (1 Reply)
Discussion started by: gravi2020
1 Replies

7. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies

8. UNIX for Dummies Questions & Answers

newbie need help to run java in UNIX

I need to run .java from a directory. i.e. c:\aaa\bbb\ccc.java first I compile all the java using javac *.java under the c:\aaa\bbb directory, now I want to run this command under cd .. , Here is the command that I need to type.. java -classpath... (5 Replies)
Discussion started by: uci
5 Replies

9. UNIX for Dummies Questions & Answers

run a java file on UNIX?

HI, I want to run my .java file on a SunOS 5.8 Unix machine. The java file is writen with Ready to Program (Similar to Jbuilder) on a PC. Thanks!! (3 Replies)
Discussion started by: leotopia
3 Replies

10. IP Networking

Run commands on a UNIX with NT

Hi I'm trying to automatically run a command on a UNIX (AIX) machine from a Windows NT 4 machine. I can do this manually using the 'rexec' or 'rsh' command but I need an automatic login (on the AIX). In the manual I've found that there should be a '.rhosts' file on the Unix machine in the... (1 Reply)
Discussion started by: Mark Detrez
1 Replies
Login or Register to Ask a Question