简体   繁体   中英

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 textFile.txt and use each of the words in place of shared-secret . If it's a success, print the word.

What I have till now is:

#!/bin/bash

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? Thanks.

Idea for the loop taken from https://stackoverflow.com/a/7721320/2193968

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM