"Fossies" - the Fresh Open Source Software Archive

Member "smslink-0.56b-3/varia/scripts/bulksms" (15 Nov 2005, 4300 Bytes) of package /linux/misc/old/smslink-0.56b-3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 #-----------------------------------------------------------
    4 # Program : bulksms                        Project : SMSLink
    5 # Author  : Philippe Andersson
    6 # Date    : 17/01/00
    7 # Version : 1.0
    8 # Notice  : (c) Les Ateliers du Heron, 2000 for Scitex Europe, S.A.
    9 # Comment : Sends bulk sms through the sendsms client program.
   10 # History : * 1.0 (17/01/00) - Initial release.
   11 #-----------------------------------------------------------
   12 # Uncomment for debugging
   13 #set -v -x
   14 
   15 # Constants
   16 
   17 # Set default parameter value
   18 GSMLIST="./gsmlist.txt"               # destination GSM list
   19 LOGFILE="./bulksms.log"
   20 MSG=""
   21 SERVER=""
   22 
   23 #***********************************************************
   24 #                     SOME FUNCTIONS
   25 #***********************************************************
   26 #***********************************************************
   27 
   28 #***********************************************************
   29 #         CODE BEGINS - GET COMMAND LINE PARAMETERS
   30 #***********************************************************
   31 # Disable filename generation while parsing parameters
   32 set -f
   33 
   34 #---------------------------------------------Get parameters
   35 while getopts :i:o:m:s: argname; do
   36   case ${argname} in
   37     i) GSMLIST=${OPTARG}
   38        ;;
   39     o) LOGFILE=${OPTARG}
   40        ;;
   41     m) MSG=${OPTARG}
   42        ;;
   43     s) SERVER=${OPTARG}
   44        ;;
   45     :) echo "bulksms: missing required value for -${OPTARG} parameter."
   46        exit 1
   47        ;;
   48     ?) echo "bulksms 1.0 - Sends bulk SMS"
   49        echo " "
   50        echo "Usage: bulksms [-i gsmlist] [-o logfile] -m message -s server"
   51        echo " "
   52        echo "where: -i = gsm file (opt. - def. ./gsmlist.txt)"
   53        echo "       -o = log file (opt. - def. ./bulksms.log)"
   54        echo "       -m = message (req. - no def.)"
   55        echo "       -s = SMS server (req. - no def.)"
   56        echo " "
   57        exit 1
   58        ;;
   59   esac
   60 done                                         # while getopts
   61 
   62 # Handle additional parameters (unused here)
   63 shift $((${OPTIND} -1))
   64 more_args=${*}
   65 
   66 # Re-enable filename generation
   67 set +f
   68 
   69 #------------------------------Check for required parameters
   70 # Message.
   71 if [ -z "${MSG}" ]; then
   72   echo "bulksms: missing required parameter message."
   73   exit 1
   74 fi
   75 
   76 # Server.
   77 if [ -z "${SERVER}" ]; then
   78   echo "bulksms: missing required parameter server."
   79   exit 1
   80 fi
   81 
   82 #----------------------------------------Validate parameters
   83 # check config. file for existence
   84 if [ ! -r ${GSMLIST} ]; then
   85   echo "bulksms: the specified file (${GSMLIST}) doesn't exist (or can't be read)."
   86   exit 1
   87 fi
   88 
   89 #***********************************************************
   90 #                  PRE_PROCESS INPUT FILE
   91 #***********************************************************
   92 echo "Processing..."
   93 
   94 if [ -x /usr/local/bin/frf ]; then
   95   # removes all trailing spaces
   96   /usr/local/bin/frf -i 0 -o 0 -f ${GSMLIST}
   97   if [ ${?} -ne 0 ]; then
   98     echo "bulksms: error while prodessing ${GSMLIST} through frf."
   99   fi
  100 else
  101   echo "bulksms : can't pre-process input file through frf (not found)."
  102   echo "          Continue with input file \"as is\"... In God we trust (?)"
  103 fi
  104 
  105 #***********************************************************
  106 #                      MAIN READ LOOP
  107 #***********************************************************
  108 if [ -r ${GSMLIST} ]; then
  109   # Write header line to output file (reset it)
  110   echo "Bulk SMS sending started $(date)." > ${LOGFILE}
  111 
  112   # Now scan input file and process it...
  113   cat ${GSMLIST} | while read in_line; do
  114     # ignores full comment lines
  115     if [ "$(echo ${in_line} | cut -c 1)" = "#" ]; then
  116       continue
  117     fi
  118 
  119     # removes comment at end of line
  120     in_line=${in_line%#*}
  121 
  122     # in case of EOL comments, should also remove trailing spaces.
  123 
  124     # ignores empty lines
  125     if [ -z ${in_line} ]; then
  126       continue
  127     fi
  128 
  129     # now process it...
  130     echo -n "Sending to ${in_line}..."
  131     echo -n "Sending to ${in_line}..." >> ${LOGFILE}
  132     sendsms -d ${in_line} -m "${MSG}" ${SERVER} >> ${LOGFILE} 2>&1
  133     retval=${?}
  134     if [ ${retval} -eq 0 ]; then
  135       echo " OK"
  136     else
  137       echo " FAIL"
  138     fi
  139     echo " " >> ${LOGFILE}
  140 
  141   done
  142 
  143   # Now close the log with a display of the current time
  144   echo "Bulk SMS sending finished $(date)." >> ${LOGFILE}
  145 
  146 else
  147   echo "bulksms: can't read ${GSMLIST} config. file."
  148   exit 1
  149 fi
  150