Monday, January 26, 2009

Shell Script Documentation, with commands output

Two months ago, I blogged about how we can have documentation built-in in the shell script. Although the shell script has sufficient documentation, sometime you may not have the privilege to run those commands to fully understand what the script is really doing. Imagine you are given the below code snippet:
for i in `someAdmCmd list | awk 'NR> 2{print $1}'`
    someAdmCmd -v list instance=$i | awk 'NR>2 && $5>0 {printf("%s Failed\n", $1)}'
You may want to know why you need to skip 2 lines and what is that 5th field suppose to be.

It would be helpful if the original script can provide listing output of someAdmCmd. You can do so by ending your script with exit 0 and follow it by whatever commands output. You don't even have to comment them out because your script will be terminated by exit 0 anyway. Just like below:

#! /bin/sh

exit 0

# someAdmCmd list
Name  Description Time
someA Something A 12:00
someB Something B 13:00

# someAdmCmd -v list instance=someA
Name Path Status Enabled Failed
someA-1 2 OK 2 0
someA-2 2 Failed 1 1
someA-3 2 OK 2 0
someA-4 2 OK 2 0

Don't you find this script self-explanatory. I certainly think so.



Post a Comment

<< Home