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. Thu Mar 28, 2024 21:21
SMSTools3 Community » Help and support Bottom

[answered] send sms from command-line with text file parameter

  This topic is locked

Page:  1

Author Post
Member
Registered:
Jun 2011
Location: Germany
Operating system name and version: Debian 6
Version of smsd: 3.1.14
Smsd installed from: sources
Name and model of a modem / phone: -
Interface: USB

hi together

everything works fine.
if i generate a message like:
echo –e “To: 49172xxxxxxx\nInclude: /home/test/sms.txt” > /var/spool/sms/outgoing/test
it works.

but i want to use a command like:
sendsms +49172xxxxxxx Include: /home/test/sms.txt
or
sendsms +49172xxxxxxx -f /home/test/sms.txt
is it possible to work with parameters?


best regards, mike

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Here is a new sendsms for you. See highlighted comments for details.

#!/bin/bash
# This script send a text sms at the command line by creating
# a sms file in the outgoing queue.

# $1 is the destination phone number.
# $2 is the message text.
# If you leave $2 or both empty, the script will ask you.
# If you give more than 2 arguments, last is taken as a text and
# all other are taken as destination numbers.
# If a destination is asked, you can type multiple numbers
# delimited with spaces.

# Additional headers can be given with -A option _before_ text:
# sendsms -A "Flash: yes" 358401234567 "This is a test SMS"
# sendsms -A Flash:yes 358401234567 "This is a test SMS"
# sendsms -AFlash:yes 358401234567 358402345678 -A "Replace: 1" "This is a test SMS"

# If using a header Include: /path/to/file, you may want to keep message
# body in the main SMS file empty. In this case use the option -z
# as the _last_ argument:
# sendsms -AInclude:/path/to/file 358401234567 -z

# Keys for example: "password" and "keke":
# KEYS="5f4dcc3b5aa765d61d8327deb882cf99 4a5ea11b030ec1cfbc8b9947fdf2c872 "

KEYS=""

# When creating keys, remember to use -n for echo:
# echo -n "key" | md5sum

smsd_user="smsd"

# Will need echo which accepts -n argument:
ECHO=echo
case `uname` in
  SunOS)
    ECHO=/usr/ucb/echo
    ;;
esac

if ! [ -z "$KEYS" ]; then
  printf "Key: "
  read KEY
  if [ -z "$KEY" ]; then
    echo "Key required, stopping."
    exit 1
  fi
  KEY=`$ECHO -n "$KEY" | md5sum | awk '{print $1;}'`
  if ! echo "$KEYS" | grep "$KEY" >/dev/null; then
    echo "Incorrect key, stopping."
    exit 1
  fi
fi

DEST=$1
TEXT=$2

if [ -z "$DEST" ]; then
  printf "Destination(s): "
  read DEST
  if [ -z "$DEST" ]; then
    echo "No destination, stopping."
    exit 1
  fi
fi

if [ -z "$TEXT" ]; then
  printf "Text: "
  read TEXT
  if [ -z "$TEXT" ]; then
    echo "No text, stopping."
    exit 1
  fi
fi

HEADERS=""

if [ $# -gt 2 ]; then
  n=$#
  while [ $n -gt 1 ]; do
    if [ "${1:0:2}" = "-A" ]; then
      hdr="${1:2}"
      if [ -z "$hdr" ]; then
        shift
        n=`expr $n - 1`
        hdr="$1"
      fi
      [ -n "$HEADERS" ] && HEADERS="$HEADERS"$'\n'
      HEADERS="${HEADERS}${hdr}"
    else
      destinations="$destinations $1"
    fi
    shift
    n=`expr $n - 1`
  done
  TEXT=$1
  [ "$TEXT" = "-z" ] && TEXT=""
else
  destinations=$DEST
fi

echo "-- "
echo "Text: $TEXT"

ALPHABET=""
if which iconv > /dev/null 2>&1; then
  if ! $ECHO -n "$TEXT" | iconv -t ISO-8859-15 >/dev/null 2>&1; then
    ALPHABET="Alphabet: UCS"
  fi
fi

owner=""
userid=`id -u`
if [ $userid -eq 0 ]; then
  if [ -f /etc/passwd ]; then
    if grep $smsd_user: /etc/passwd >/dev/null; then
      owner=$smsd_user
    fi
  fi
fi

for destination in $destinations
do
  echo "To: $destination"

  TMPFILE=`mktemp /tmp/smsd_XXXXXX`

  $ECHO "To: $destination" >> $TMPFILE
  [ -n "$ALPHABET" ] && $ECHO "$ALPHABET" >> $TMPFILE
  [ -n "$HEADERS" ] && $ECHO "$HEADERS" >> $TMPFILE
  $ECHO "" >> $TMPFILE
  if [ -z "$ALPHABET" ]; then
    $ECHO -n "$TEXT" >> $TMPFILE
  else
    $ECHO -n "$TEXT" | iconv -t UNICODEBIG >> $TMPFILE
  fi

  if [ "x$owner" != x ]; then
    chown $owner $TMPFILE
  else
    if [ $userid -gt 0 ]; then
      chmod 666 $TMPFILE
    fi
  fi

  FILE=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
  mv $TMPFILE $FILE
done
 
 
'bash' Syntax Highlight powered by GeSHi


Member
Registered:
Jun 2011
Location: Germany
Topic owner
you're just great!! works like a charm.. thanks!
you will receive a donation the next days..
stay tuned, mike

  This topic is locked

Page:  1

SMSTools3 Community » Help and support Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.