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.

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

Lets break these down. The first command, tomst , will start up your tomcat using the script. Depending on your setup, you might prefer to use the 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 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.