-1

I expect my program run as such when run a start up script:

/opt/bin/java -Dgroup.profile=GROUP_270731 -Dother=other xxx.xxx.MainClass

while my script is like

#!/bin/shell

JAVA_OPTS=getOpts

${JAVA_HOME}/bin/java $JAVA_OPTS $OTHER_ARGS xxx.xxx.MainClass

getOpts(){
  # get java opts from certain file java_opts
}

All that I could change is just the java opts file, in which I have to fetch a group info in a certain file, I did this in my java opts:

-Dgroup.profile=$(cat /home/admin/conf/deploy.conf | sed 's|[[:blank:]]||g' | grep group.profile= | cut -d= -f2)) -Dother.args

However, I got such err log:

cannot find or load main class .home.admin.conf.deploy.conf

It seems something went run in my java_opts cmd.

Lo1nt
  • 17
  • 1
  • 3
  • What is the exact output of the command inside `$()`? – user207421 Feb 15 '22 at 03:47
  • string like GROUP_004134213 – Lo1nt Feb 15 '22 at 04:04
  • Your #! line is nonsense. `#!/bin/shell` .... what shell is this supposed to be? At least I don't know any shell which is named _shell_. Actually, for your problem, I strongly sugget that you are using a shell which can do arrays (for instance zsh), because the typically solution would be to store the Java options into the array and expand the array when calling java. – user1934428 Feb 15 '22 at 07:53
  • Use `echo ` to print the entire command line, or if your shell supports it `set -x` – DuncG Feb 15 '22 at 08:35
  • 1
    We don’t know the contents of your `deploy.conf` or what these transformations are supposed to do. It raises the question why you don’t keep a file in the format you actually need instead of transforming an unsuitable file on each invocation. As a side note, instead of `cat file | sed op | …` you can use `sed op file | …` in the first place. And generally, instead of `cat file | command`, you can almost always use `command – Holger Feb 15 '22 at 08:36

1 Answers1

0

Suggesting to fix your script:

#!/bin/shell
getOpts(){
  # get java opts from certain file java_opts
  echo "JAVA_OPTS values in one long string."
}
JAVA_OPTS="$(getOpts)"

# for debug use `set -x` and `set +x` view the actual executed command.
set -x
${JAVA_HOME}/bin/java "$JAVA_OPTS" $OTHER_ARGS xxx.xxx.MainClass
set +x
Dudi Boy
  • 4,551
  • 1
  • 15
  • 30