Home > Back-end >  In a ksh script find value of latest file/jar and save to a variable
In a ksh script find value of latest file/jar and save to a variable

Time:03-02

I am a self-confessed beginner level when it comes to RHEL and I can navigate around, find things, run things etc. And I only have basic permissions on my DEV, INT, PROD and BCP servers at my client as most of my time is taken up in complex development.

I use ksh scripts to launch Tomcat, and for the new version of my project it is a SpringBoot launchable JAR file. New deployments will feature a dynamically changing jar/file name deployed from Nexus such that instead of the fixed name (in the older Tomcat setup for exploded folder in /webapps) I will need to look it up as it'll have a changing version number at the end.

I came up with this:

find . -name bondac*.jar | awk '{print substr($1,3);}'

Which works on CLI, so I added it to my launch ksh file (which worked previously with fixed jar name) like so:

jartolaunch = find . -name bondac*.jar | awk '{print substr($1,3);}'
java -jar $jartolaunch --spring.config.location=/data/chronos/activepivot/config/application.yml && sleep 1 && check_process $1

However this gives the error, when ksh is run, of 'jartolaunch not found'.

CodePudding user response:

Change:

jartolaunch = find . -name bondac*.jar | awk '{print substr($1,3);}'

to:

jartolaunch=$(find . -name bondac*.jar | awk '{print substr($1,3);}')

or better:

jartolaunch=$(find . -name bondac*.jar -printf '%P\n')
  • Related