0

I have a jar file which I can call the following way: java -jar myjar.jar param1 param2 param3

Now I need a bash script which waits until some clock time is reached (e.g. 5pm) and then calls this jar file several times, lets say 5 times (so that I have 5 JVMs running). Moreover, the arguments passed to the bash script should be passed to the jar. Then, after some times (e.g. 10 minutes), all the started java programs should be killed.

How can I do this?

Thank you very much.

2
  • Is it a possibility to register the bash script as a service in Windows, that starts daily at 17:00? Or is that not the kind of behaviour you're looking for? Commented Oct 14, 2014 at 20:28
  • Do you need it to run at 5pm every day? (use cron) Or just today? (use at) Commented Oct 14, 2014 at 21:17

3 Answers 3

2

a bash script which waits until some clock time is reached (e.g. 5pm) and then calls this jar file several times, lets say 5 times

UPDATE: Many thanks to Glenn Jackman, I incorporated his answer

#!/bin/bash

cat<<EndBlock | at 5pm
for i in {1..5}; do
    java -jar myjar.jar "$@" &
    pid=$!
    { sleep 600 && kill $pid; } &
done
EndBlock
Sign up to request clarification or add additional context in comments.

Comments

2

Create a bash script to invoke the method . and add an cron entry to execute at specific time.

1 Comment

And I think regarding stopping program after 10 minutes should be implemented through java.
2

A variation on @thom's answer, where an arbitrary number of arguments is passed, and the spawned jvm is killed after 10 minutes.

for i in {1..5}; do
    java -jar myjar.jar "$@" &
    pid=$!
    { sleep 600 && kill $pid; } &
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.