Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
#! /Bin/bash
#
# Simple call generator which uses asterisk (www.asterisk.org)
# To generate CILS.
#
# This program is free software, distributed under the terms
# The GNU General Public License.
#
# Parameters of the call Generator
#
Callfile = ""
Callspool = ""
Callminw = "" # in seconds
Callmaxw = "" # in seconds
No_args = 0
If [$ #-EQ "$ no_args"] # script invoked with no command-line ARGs?
Then
Echo "Usage: 'basename $ 0' [-fs12]"
Echo "-f the call file to use ."
Echo "-S the asterisk call spool directory ."
Echo "-1 The minimum time in seconds to wait before initiating a call ."
Echo "-2 The maximum time in seconds to wait before initiating a call ."
Exit 1
Fi
#
# Get options from Command Line
#
While getopts ": F: S: 1: 2: V" option
Do
Case $ option in
F)
Callfile = $ optarg
;;
S)
Callspool = $ optarg
;;
1)
Callminw = $ ($ optarg ))
;;
2)
Callmaxw =$ ($ optarg ))
;;
Esac
Done
# Echo "Call file: $ callfile"
# Echo "spool directory: $ callspool"
# Echo "minimum time: $ callminw second (s )"
# Echo "maximum time: $ callmaxw second (s )"
#
# Do some parameters checking
#
If [-z "$ callfile"]; then
Echo "no call file? "
Exit 1
Else
If [! -F $ callfile]; then
Echo "Call File '$ callfile' does not exist ."
Exit 1
Fi
Fi
If [-z "$ callspool"]; then
Echo "no call spool directory? "
Exit 1
Else
If [! -D "$ callspool"]; then
Echo "Call spool directory '$ callspool' does not exist ."
Exit 1
Fi
Fi
If [-z "$ callminw"]; then
Echo "no min call waiting time? "
Exit 1
Fi
If [-z "$ callmaxw"]; then
Echo "No Max call waiting time? "
Exit 1
Fi
If [$ callminw-GT $ callmaxw]; then
Echo "inappropriate values for Min and Max call waiting times ."
Exit 1
Fi
Callno = "1"
Randmax = "32767"
Randop = $ (randmax/callmaxw ))
Time = "0"
CPS = "0"
Cps_string = "-"
While [1]
Do
# Get a random number between callminw... callmaxw
# Note: use Bash's random variable (generates a random between 0... 32767)
# Note: If the limits have the same value, always return that value
If [$ callmaxw-EQ $ callminw]; then
Res = $ callmaxw
Else
While [1]
Do
Rand = $ random
Res = $ (RAND/randop ))
If [[$ res-ge $ callminw]; then
If [[$ res-Le $ callmaxw]; then
Break
Fi
Fi
Done
Fi
# Generate a call after a random time interval
Echo "[call $ callno, time $ time, CPS $ cps_string] waiting $ res second (s )..."
Sleep $ res
CP-F "$ callfile" "$ callspool/callgen $ random"
# Update stuff
Callno = $ (++ callno ))
Time = $ (Time + Res ))
CPS = $ (callno * 100/time ))
Cps_string = $(CPS/100 )). $ (CPS % 100)/10) $ (CPS % 100) % 10 ))
Done
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/