Introduction

Shell scripts allow sys-admins to write utility programs to speed up recurrent administration tasks. Usually they are faster compared to an equalent version from a traditional programming language & provides the expected functionality using few lines of code.
 
But often these scripts can only be accessed using a shell console. Following tutorial shows how you can extend the accessibility scope of your shell scripts by using WSO2's Web Services Application Server(WSAS).
 
This solution exposes shell scripts as web services, thus broadening the accessibility scope of your shell scripts. worried about the security?...WSAS has many options to secure services deployed on top it. So your guranteed that only users/systems withrequired credentials access your shell scripts.
 
Be creative & lying head are amazing monitoring/administration opportunities, waiting to be unleashed by YOU!!!.

 

It's just few steps away...Let's get started

Step 1 : Download latest version of WSAS (2.2.1 as of now)- http://wso2.org/projects/wsas/java
Step 2 : Download shellscriptdeployer-0.1.jar.zip attached bellow & extract it to a temporary location
Step 3 : Extract WSAS distribution to a location of your choice - Hereafter this location will be reffered as WSAS_HOME
Step 4 : Copy shellscriptdeployer-0.1.jar (from step2) to WSAS_HOME/lib/patches 
Step 5 : Open WSAS_HOME/conf/axis2.xml 
Step 6 : Add following line,
<deployer extension="sh" directory="shellservices" class="org.wso2.deployers.ShellScriptDeployer"/>

after

<axisconfig name="AxisJava2.0"> 

element.

Step 7 : Create a folder called 'shellservices' inside WSAS_HOME/repository.

Step 8 : Create a BASH script called 'DiskUsageMonitor.sh' & save it inside WSAS_HOME/repository/shellservices folder
Step 9 : It should contain following text.
#!/bin/bash

#@webservice.name=DiskUsageMonitor
#@webmethod.name=getUsage
#@webmethod.param1=location

echo "-----------------------------"
echo "Results of disk usage search"
echo "-----------------------------"

du --max-depth=1 -m $1
Step 10 : Try executing this simple script from command line & observe the result.

eg:
./DiskUsageMonitor.sh /tmp
Step 11 : Now lets see how WSAS can extend the accesibility scope of our script. First start WSAS server by executing WSAS_HOME/bin/wso2wsas.sh
 
Step 12 : Open up a browser window & enter following URL.
 
Results

Note : 9762 is the default port unless you have changed.
 
Step 13 : You will see the output of your shell script in the browser. Try using alternative values for '/tmp'.

eg:



Detailed analysis of DiskUsageMonitor.sh

It is a typical BASH script, except for following three non-executing entries.

#@webservice.name=DiskUsageMonitor
#@webmethod.name=getUsage
#@webmethod.param1=location



if your script has multiple input parameters, you can add them as follows.

#@webservice.name=DiskUsageMonitor
#@webmethod.name=getUsage
#@webmethod.param1=location
#@webmethod.param2=max-depth
#@webmethod.param3=block-size

Make sure you increment the number after 'param' for every new parameter. 

Limitations as of this release

This project is in inception stages. Therefore several must have functionalities are still being developed.

  • WSDL for the service is not generated correctly
  • Support for DOS bat files is not enabled in this release
  • Multiple extensions of scripts are not supported (A limitation comming from Axis2)
  • Scripts need to be copied to WSAS_HOME/repository/shellservices
  • REST support is not available