I am trying to start or stop a service on AIX in ksh.
I am trying to start to build in fool proofing for checking things like if the services is already down, etc.
Here is my script
#!/bin/ksh
#################################################################################
# PARAMETERS & VARIABLES SECTION #
#################################################################################
DBI_LOC="DBI/InstallCollector/dbi_collector/bin"
#Put input option to upper case.
OPTION=$( echo "$1" | tr "[:lower:]" "[:upper:]" )
#################################################################################
# FUNCTION SECTION #
#################################################################################
parseresults() {
typeset RESULT="$1"
if [ "${OPTION}" = "START" ] ; then
case "${RESULT}" in
*)
echo "Success"
;;
esac
else
case "${RESULT}" in
DBI.(Collector is not running))
echo "Collector is already down. Continuing..."
;;
DBI.(performance data collector shutdown COMPLETE))
echo "Success shutting down collector. Continuing..."
;;
*)
echo "Error shutting down the collector. Exiting with error."
exit 1
;;
esac
fi
}
#################################################################################
# MAIN SCRIPT SECTION #
#################################################################################
case "${OPTION}" in
"START")
echo "Starting the collectors..."
RESULT=$(ksh ~/${DBI_LOC}/start_dbi_collector.sh)
;;
"STOP")
echo "Stopping the collectors..."
RESULT=$(ksh ~/${DBI_LOC}/stop_dbi_collector.sh)
;;
*)
echo "Error: No Parameter specified. Must be either start or stop"
exit 1
;;
esac
echo ${RESULT}
parseresults ${RESULT}
echo
echo
I can't seem to get it to match on the two DBI phrases. Both of those are possible outputs from their stop script. I want to consider those successes, but anything else a possible failure.
I'm still learning regex (and its differences in Java vs ksh, etc.) so you'll have to excuse my rustiness. What am doing wrong? And in your answer could you please explain why mine doesn't work and the right answer does. (I'm a proponent of the whole if you teach someone to fish thing....)
EDIT: I'm thinking it has something to so with the parenthesis. I have another script which had the same problem of hanging, but when I removed the parens, the function quite hanging. So my trick is still how to do matching on phrases....