LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-05-2020, 04:33 AM   #1
bealefay
LQ Newbie
 
Registered: Feb 2020
Posts: 2

Rep: Reputation: Disabled
How to change the path location within the shell script?


I am trying to find the installed tomcat version and location of the server.xml file to get the tomcat port number.
Using below script to do that.
Code:
#!/usr/bin/env bash

var1=$(find / -name "version.sh" ! -size 0 2>&1 |egrep -v "tmp|docker")

for loc1 in $var1
do
    abc=$(echo "$loc1" | rev | cut -c 11- | rev)
    tomcat_version=$(cd "$abc";./version.sh | grep "Server number:" | awk '{print $3}')
    tomcat_status=`tomcat`

    if [ "$tomcat_version" != "" ];then
    echo $tomcat_version
     echo "$abc"
     

    break
    fi
done
but in order to get the port number i want to change from tomcat/bin to tomcat/conf location.
For that i tried to use below synatx but it's not working.

echo "$(cd "$abc";../..)"

Can someone please suggest how to change the path ?
 
Old 02-05-2020, 04:58 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
I'm not sure if I read it correctly but I think a lot of that could be offloaded on to the find utility.

Code:
#!/bin/sh

find ./ \
        -path '*docker*' -prune -o \
        -path '*tmp*' -prune -o \
        -name 'version.sh' \
        -execdir ./tomcat \; \
        -execdir awk '/Server number:/{print $3}' {} \; 

exit 0
 
1 members found this post helpful.
Old 02-05-2020, 07:36 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,597

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
Quote:
Originally Posted by bealefay View Post
I am trying to find the installed tomcat version and location of the server.xml file to get the tomcat port number.
Using below script to do that.
Why?

What is the overall problem you are trying to solve?

If you're looking for "the" installed Tomcat, then what makes you think the port isn't the default?

What happens when there's more than one Tomcat installed and your command picks the wrong one first?

 
1 members found this post helpful.
Old 02-05-2020, 07:51 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Welcome to LQ.
Quote:
Originally Posted by bealefay View Post
Can someone please suggest how to change the path ?
"cd <path>" - in your script.

However you may not need to do this.
Quote:
Originally Posted by bealefay View Post
I am trying to find the installed tomcat version and location of the server.xml file to get the tomcat port number.
The whole locating of version.sh may be a loaded problem. Who's to say if there aren't several version.sh and six of the several are not related to Tomcat.

Perhaps you ought to find out the execution location for tomcat. I'm not familiar with running it, but whatever you would use to run it, you could use the "which" command to find out the path for it. You could next test that path to find out the existence, or not, of version.sh, and then you can run that script and parse the output. All of this you can do either by changing directory in your script, as shown above in my top statement how to change the path, or you can likely do that all without changing the path and just run version.sh using the fully qualified pathname for it.

As in the command line, you can run a program if you're in the directory for it, or you can run it using the path for it. And further, if the executable is in your actual $PATH environment variable, then you can run it anyways, without specifying the path. As always, I'd recommend what several may also say, to script defensively, using no assumptions, and just use the full paths as much as possible.

Edit additional:
And what executable (Tomcat) does not support command line arguments such as -v, --version, or similar? In short, why would you need the version.sh script. Or it is solely doing the command line switches? Review that script and figure out why it is anything special.

Last edited by rtmistler; 02-05-2020 at 07:55 AM.
 
Old 02-05-2020, 08:26 AM   #5
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,597

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
The Tomcat version.sh ultimately executes "{samedir}/catalina.sh version" (which itself puts together a java command to execute).

So a safer way to determine Tomcat version would be something like:

Code:
for f in $(find / -path '*tomcat*/bin/catalina.sh')
do
	"$f" version | awk '/Server number:/{print $3}'
done
That'll output all version numbers for Tomcat instances with the word tomcat in their path - that excludes (for example) instances within Atlassian products where the directory is named otherwise, but still can't guarantee that the desired instance is in a predictable position.


Last edited by boughtonp; 02-05-2020 at 08:28 AM.
 
Old 03-15-2020, 10:15 PM   #6
bealefay
LQ Newbie
 
Registered: Feb 2020
Posts: 2

Original Poster
Rep: Reputation: Disabled
Forgot to thank.
Thank you all for your feedback and help.
 
Old 03-16-2020, 12:41 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by bealefay View Post
Forgot to thank.
Thank you all for your feedback and help.
If you think your problem is solved please mark the thread solved. Also if you really want to say thanks just click on yes.
 
Old 03-16-2020, 03:01 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
And if you really really want to say thanks, give back to the community:
Tell us how you SOLVED it. Others will benefit.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
question: 'onclick' within 'onmouseover' within 'form' within 'table' - how is it possible? rblampain Programming 4 04-25-2017 08:49 PM
LXer: Google I/O Android News: Location, Location, Location (Plus Cloud Messaging and Bluetooth) LXer Syndicated Linux News 0 06-05-2013 01:00 PM
script to read path from console and used to change the script execution path vdamgo Linux - General 5 02-12-2013 02:18 PM
help with execute mulitple shell script within shell script ufmale Programming 6 09-13-2008 12:21 AM
location, location, location! mermxx LQ Suggestions & Feedback 9 09-25-2004 03:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration