echo-test-single-instance.sh script

The echo-test-single-instance.sh script helps you understand the script output format. The script generates a random number between 0 to 100. This number is used as the KM value. The random number value is displayed in text in the annotation. 

This script is available at $PATROL_HOME\..\TRO\Conf\Scripts\Samples directory. The script content is as follows:

#!/bin/sh -f
#=======================================================================================================
# This sample is provided as a 'hello world' kind of script.
# One which help the KM user understand the required format of script output.
# Every time the script is called, it generates a random number in the range of 0..100
# That number is used as value for the KM.
# Annotation is then added printing text converting the digits of that random number into words.
#
# In this case the script is printing in format what would allow a single value with multi-line annotation
# the format is:
# <numeric value>
# <some annotating text>
#=======================================================================================================
function number_to_words
{
	echo ${1}
	ANNOTATION="Your number ${1} in words is:"
	for line in $(echo $1 | sed -e 's/\(.\)/\1\n/g')
	do
		case $line in
		0) ANNOTATION="$ANNOTATION zero " ;;
		1) ANNOTATION="$ANNOTATION one " ;;
		2) ANNOTATION="$ANNOTATION two " ;;
		3) ANNOTATION="$ANNOTATION three " ;;
		4) ANNOTATION="$ANNOTATION four " ;;
		5) ANNOTATION="$ANNOTATION five " ;;
		6) ANNOTATION="$ANNOTATION six " ;;
		7) ANNOTATION="$ANNOTATION seven " ;;
		8) ANNOTATION="$ANNOTATION eight " ;;
		9) ANNOTATION="$ANNOTATION nine " ;;
		esac 
	done
	len=`echo $ANNOTATION | wc -c`
	padding=`printf '=%.s' $(eval "echo {1.."$(($len))"}")`
	ANNOTATION="$padding\n$ANNOTATION\n$padding"
	echo -e $ANNOTATION
}
RANDOME_NUMBER=`printf "%.0f\n" $(echo "scale=2;$RANDOM / 32767*100" | bc)`
number_to_words $RANDOME_NUMBER
Was this page helpful? Yes No Submitting... Thank you

Comments