#!/bin/bash
#
#
#    Scalix Public License
#
#
#    The contents of this file are subject to the Scalix Public License
#    Version 1.1 ("License"); you may not use this file except in
#    compliance with the License. You may obtain a copy of the License at
#
# 
#    http://www.scalix.com/community/licensing 
#
# 
#    Software distributed under the License is distributed on an "AS IS"
#    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
#    the License for the specific language governing rights and limitations
#    under the License.
#
# 
#    The Original Code is Scalix Server. 
#    The Initial Developer of the Original Code is Scalix Corporation. 
#    Copyright (C) 2006 Scalix Corporation. 
#    All Rights Reserved.
#    Additional Copyrights may apply - see the notice in each file
#
#
#
#
#
# Copyright (C) 2006 Scalix Corporation.  All Rights Reserved.
#
# This is a simple plugin template that can be used as example to build or write other 
# plugins. Note that each plugin must have the --help option, regarless of number of 
# arguments.
# Please consult the Plugin Development Guide for further details
# -- Jules Damji, SAC Team
#
# usage function to pring usage information. Note this must exist with non-zero status.
# preferably greater than 1.
#
usage() {
	echo "usage: $0 [--help]"
	exit 2
}
#
# This MUST be part of all Plugins. The format for the output must be adhered to
# as specified in the development guidelines.
# VERSION for Equinox must be "1.0"
# All five tokens NAME:, VERSION, DESCRIPTION, PARAMETERS, and OUTPUT must be
# part of this help() funtion. 
# Subsitute appropriate values for your plugin here.
#
function help {
	echo ""
	echo ""
	echo "VERSION:"
	echo "1.0"
	echo ""
	echo "NAME:" 
	echo "Check CPU Usage"
	echo ""
	echo "DESCRIPTION:"
	echo ""
	echo "This script check the cpu usage on the server."
	echo "The command used is part of top."
	echo ""
	echo "PARAMETERS:"
	echo "-t	seconds	5	number	single	Number of seconds before taking the next sample"
	echo "-s	samples	5	number	single	Number of samples"
	echo "--help	Help	\"\"	\"\"	\"\"	Usage Information"
	echo ""
	echo "OUTPUT:"
	echo "text/plain"
}
#
# function to fetch the load on the CPU
# args: num is the number of samples
# args: slp seconds before the next sample
function doLoad {
local num=$1
local slp=$2
	i=1
	while [ "$i" -le $num ]
	do
		echo `uptime`
		sleep $slp
		i=`expr $i + 1`
	done
}
#
# main srcript
#
sample=3
tout=5
for i in "$@"
do
	case $i in
		--help) 
			help
			exit 0
			;;
		-t) 
	 		tout="$2"
			shift 1
			;;
		-s)
			sample="$2"
			shift 1
			;;
		[0-9])
			shift
			;;
		*)
			usage
	esac
done
doLoad $sample $tout
exit 0
