Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In a ksh script find value of latest file/jar and save to a variable

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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’.

>Solution :

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading