Wednesday, February 16, 2011

[Linux - Ubuntu] Creating Shell Script

Below is an easy and simple way to create a shell script for Ubuntu (Linux). 

1. Example is to stop Tomcat, copy some application files and start Tomcat. Write following sample Linux commands in a file and save it as <shell-script>.sh

#!/bin/sh
echo Deploying JAVA Application

echo Stopping Tomcat Service...
cd /usr/local/tomcat/bin
./catalina.sh stop

echo
echo

echo Copying Application Files...
cd <source-directory>
cp -R * <destination-directory>
rm <some-file-name>.<extension>
mv <source-file-name>.<extension>  <destination-file-name>.<extension>

echo
echo

echo Deployment Compelted. Starting Tomcat Service...
cd /usr/local/tomcat/bin
./catalina.sh start

echo
echo

2. Grant permissions to this file:
chmod 777 <shell-script>.sh

3.  Run this shell script as:
./<shell-script>.sh

4. Now, use following command to get the Catalina Logs to assure everything is working fine:
tail -f /usr/local/tomcat/logs/catalina.out

... and that's it.

No comments:

Post a Comment