Sai
Sai

Reputation: 376

How to integrate Spring batch command line invocation in a shell script

I am having a spring batch application, that is invoked through the command line. I would want to put that invocation in a shell script, so that I can run a script rather than the entire command.

For example, my invocation looks like:

java -jar run=1

The problem is for each run, the job parameter needs to be incremented. Is there a way through which i can achieve that in a shell script?

Thanks

Upvotes: 1

Views: 4759

Answers (2)

Serkan Arıkuşu
Serkan Arıkuşu

Reputation: 5619

You need an incrementer for this as usual.

<bean id="simpleIncrementer"
class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>
<job id="myJob" incrementer="simpleIncrementer">
</job>

The trick for this incrementer to work with CommandLineJobRunner is adding the -next parameter when running the task.

-next: (optional) to start the next in a sequence according to the JobParametersIncrementer in the Job

Something like this:

java –jar myjob.jar jobs/myjob.xml myjob -next

Upvotes: 2

arutaku
arutaku

Reputation: 6087

You can do it n times (in a terminal) using a for loop this way:

for i in {1..10}; do java -jar run=$i; done

Upvotes: 1

Related Questions