jeet jeet - 1 year ago 115
Bash Question

Run Jar Using Shell Script

So I have a Java file that needs this following string to run.

java --classpath=$CLASSPATH:/path/to/jradius-client.jar net.sourceforge.jradiusclient.TestRadiusClient hostname authport acctport shared-secret username password

What I need to do is to write a script that uses space separated words from a certain
and use each of the words in place of
. If it's a success, print the word.

What I have till now is:


java --classpath=$CLASSPATH:/path/to/jradius-client.jar net.sourceforge.jradiusclient.TestRadiusClient "val" 1812 1813 shared-secret username password

exit $?

What I want is something like this (in Java like pseudo-code, I have no bash experience :( ):

String s = Words From Text File As String
String[] words = s.split("\\W+");
for(word : words){
try and run The JAva .jar File With Params X, Y, word, Z
success? print word

How can I achieve this?

Answer Source

Idea for the loop taken from

for word in $(<textFile.txt)
    java --classpath=$CLASSPATH:/path/to/jradius-client.jar net.sourceforge.jradiusclient.TestRadiusClient hostname authport acctport $word username password

This will read every word from every line in textfile.txt and put it into word and then run the command substituting $word with the value read from the file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download