Some quick tomcat shell functions

Here are some bash profile functions to help you use tomcat as a pro. The following needs to be done in either your
.profile file or
.bash_profile, depending on what shell you have and whichever method you prefer. First off, make sure you have exported
CATALINA_HOME variable pointing to the base of your tomcat installation.

Shell

1

export CATALINA_HOME=/opt/tomcat

Once you’ve got that done, you can define the following shell functions.

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

functiontomst(){

${CATALINA_HOME}/bin/startup.sh

}

functiontomsh(){

${CATALINA_HOME}/bin/shutdown.sh

}

functiontomlog(){

less${CATALINA_HOME}/logs/catalina.out

}

functiontomls(){

ls-l${CATALINA_HOME}/webapps|grep-v.war$

}

functiontomlogf(){

tail-f${CATALINA_HOME}/logs/catalina.out

}

functiontomps(){

ps-ef|greptomcat|grep-vgrep|cut-d' '-f2

}

functiontomkill(){

kill`tomps`

}

Lets break these down. The first command,
tomst , will start up your tomcat using the
startup.sh script. Depending on your setup, you might prefer to use the startup.sh script over the service command. This is a neat way to do it from any directory.

Next is the
tomsh command which will help you shut down your tomcat container. Again, like the previous command, this is using the
shutdown.sh script instead of the service command. You could replace both of these with the service commands if you prefer.

The
tomlog and
tomlogf commands both display the
catalina.log log file, however the
tomlogf command will follow (
tail) the log.

The
tomls command will show whats in your webapps directory. Now, this command will only show you your war files so these might not necessarily be deployed, but its a good way to list your deployments.

The
tomps command will show you the process ID of the running tomcat container. As of this moment, this only looks for the keyword tomcat in your processes. If you have multiple tomcat containers running, you will have to make the
grep more specific.

Lastly, the
tomkill command effectively runs the
tomps command but with a prefix of a kill command, effectively executing a kill on your tomcat process.