Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1669  / 3 Years ago, tue, november 2, 2021, 2:44:02

I have some runnable-jar files. I want to run them at regular intervals and also kill those processes after some time. I am a newbie when it comes to Ubuntu or linux in general. Can anybody suggest me the best practice to achieve it?


More From » java

 Answers
1

Use something like



#!/bin/bash
java -jar <name-of-the-jar-file> &
javapid=$!
sleep <some-time-in-seconds>
kill $javapid


in a file, make it executable (chmod +x ) and run it using



./<filename>


This will start the jar-file and kill it after some time. There are several ways to excecute the command at regular intervals. You could use cron ( http://help.ubuntu.com/community/CronHowto ) to always excecut it as long the computer is runnig. Or use a simple shell script loop to start the execution from the command line:



#!/bin/bash 
COUNTER=0
while [ $COUNTER -lt 100 ]; do
<same as above without the first line>
let COUNTER=COUNTER+1
done


This will run the command 100 times, you could stop the execution simply by pressing ctrl-c.


[#43562] Wednesday, November 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rontablis

Total Points: 293
Total Questions: 123
Total Answers: 104

Location: Austria
Member since Mon, Mar 1, 2021
3 Years ago
;