SMS Server Tools 3
This site is hosted by Kekekasvi.com
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. Please login or register. Fri Mar 29, 2024 14:54
SMSTools3 Community » Sample scripts / setups Bottom

Sample script for load balancing using the checkhandler

Login and Post Reply

Page:  1

Author Post
Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
This sample script for load balancing was published at 2008 inside the package. It had fixed coding for modems GSM1, GSM2 and GSM3.

The new version here has array for modems and queues, and is therefore easier to take to use.

#!/bin/bash
# ---------------------------------------------------------------------------------------
# This example is for three modems, named GSM1, GSM2 and GSM3 using queues Q1, Q2 and Q3.
# In the global part of smsd.conf, enable message counters:
# stats = /var/spool/sms/stats
# Use zero value for interval if statistics files are not used:
# stats_interval = 0
#
# Enable checkhandler (this script):
# checkhandler = /usr/local/bin/load_balancing.sh
#
# Define queues:
# [queues]
# Q1 = /var/spool/sms/Q1
# Q2 = /var/spool/sms/Q2
# Q3 = /var/spool/sms/Q3
#
# With smsd >= 3.1.7 providers are not needed to define,
# with previous versions define the following:
# [providers]
# Q1 = 0,1,2,3,4,5,6,7,8,9,s
# Q2 = 0,1,2,3,4,5,6,7,8,9,s
# Q3 = 0,1,2,3,4,5,6,7,8,9,s
#
# Add queue definition for each modem:
# [GSM1]
# queues = Q1
# etc...
# ---------------------------------------------------------------------------------------

# Settings for this script:
STATSDIR=/var/spool/sms/stats
MODEMS=( GSM1 GSM2 GSM3 )
QUEUES=( Q1 Q2 Q3 )

# ---------------------------------------------------------------------------------------

NUMBER_OF_MODEMS=${#MODEMS[@]}
NUMBER_OF_QUEUES=${#QUEUES[@]}
if [ $NUMBER_OF_MODEMS -ne $NUMBER_OF_QUEUES ]; then
  echo "ERROR: Number of queues does not match number of modems."
  exit 1 # Message is rejected.
fi

read_counter()
{
  local RESULT=0
  local FILE=$STATSDIR/$1.counter
  local COUNTER=0

  if [[ -e $FILE ]]
  then
    COUNTER=`formail -zx $1: < $FILE`
    if [ "$COUNTER" != "" ]; then
      RESULT=$COUNTER
    fi
  fi

  # Fix 23.7.2017: Use echo output, return value is limited to 255:
  #return $RESULT
  echo $RESULT
}

# If there is Queue (or Provider) defined, load balancing is ignored:
QUEUE=`formail -zx Queue: < $1`
if [ -z "$QUEUE" ]; then
  QUEUE=`formail -zx Provider: < $1`
  if [ -z "$QUEUE" ]; then

    # Read current counters:
    for ((i = 0; i < $NUMBER_OF_MODEMS; i++)); do
      # Fix 23.7.2017: Get echo output:
      #read_counter ${MODEMS[${i}]}
      #eval COUNTER_${MODEMS[${i}]}=$?
      tmp=$(read_counter ${MODEMS[${i}]})
      eval COUNTER_${MODEMS[${i}]}=$tmp
    done

    QUEUE=${QUEUES[0]}
    tmp=COUNTER_${MODEMS[0]}
    COUNTER=${!tmp}
    for ((i = 1; i < $NUMBER_OF_MODEMS; i++)); do
      tmp=COUNTER_${MODEMS[${i}]}
      tmp=${!tmp}
      if [ $tmp -lt $COUNTER ]; then
        QUEUE=${QUEUES[${i}]}
        tmp=COUNTER_${MODEMS[${i}]}
        COUNTER=${!tmp}
      fi
    done

    TMPFILE=`mktemp /tmp/smsd_XXXXXX`
    cp $1 $TMPFILE
    formail -f -I "Queue: $QUEUE" < $TMPFILE > $1
    unlink $TMPFILE
  fi
fi
exit 0
 
 
'bash' Syntax Highlight powered by GeSHi



« Last edit by keke on Sun Jul 23, 2017 20:24, 81 months ago. »
Member
Registered:
Apr 2011
Location: Iran
hello
How can we use the program you mentioned?

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Topic owner
alireza976 wrote
How can we use the program you mentioned?

When you changed the configuration like the instruction said in the begin of script, and changed MODEMS and QUEUES in the script, your setup still did not work? What kind of errors did you see, if any?

Member
Registered:
Apr 2011
Location: Iran
My issue was solved
tnx

Member
Registered:
Dec 2011
Location: SPb, Russian Federation
Thank you. SMS server ry good and the right product!

Function return result from 0 to 255.
If value count is more 255 for any modem - algoritm is broken.
If value is 256 then function return is 0, and this modem is a top priority for send.

PS: Sorry for bad English. :oops:
why message_count_clear option does not work, ver. smsd 3.1.11?
additionally required to use the option message_limit?

Member
Registered:
Dec 2011
Location: SPb, Russian Federation


Member
Registered:
Dec 2011
Location: SPb, Russian Federation
I'm sorry, the editing has expired ... :(

Member
Registered:
Aug 2009
Location: Mexico DF, Mexico
Hello all,

Im using this script, this work fine if i send sms one to one, if i send a lot of sms at same time, the counters
doesnt refresh on each sms and all sms go to GSM1.

I try to put an "sleep 1" to begining of script but this doesnt work, any idea?

Regards

Cristian

Member
Registered:
Dec 2012
Location: Cáceres, Brazil
cristian_rougier ¿Cómo te las arreglas para resolver este problema que estoy teniendo el mismo problema que los SMS están saliendo sólo por las pruebas módem GSM1'm ahora sólo 3 modems pero puse va a 10 o 20 años y quisiera saber cómo puedo enviarle un modem SMS o SMS sin serie 1 para SMS módem GSM1 2 para GSM2 módem, etc así que por favor dame un posible retorno necesito su ayuda, gracias y que Dios los bendiga.

Login and Post Reply

Page:  1

SMSTools3 Community » Sample scripts / setups Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.