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. Tue Jun 25, 2024 16:12
SMSTools3 Community » Sample scripts / setups Bottom

Network SMS

Login and Post Reply

Page:  1

Author Post
Member
Registered:
Apr 2010
Location: Germany
Hello there,

i'd like to introduce myself with a way to send SMS over TCP/IP.

Comments and enhancements welcome!!

Ok, i start with the bash-script:
#!/bin/bash

echo PASSWORT:
read PASS
PASS=(`echo $PASS | tr -d [:cntrl:]`)
if [ "$PASS" = "12345" ]; then
TMPF=(`tempfile`)
echo To: >> $TMPF
echo NUMMER:
#add error treatment
read nummer
#add error treatment
echo TEXT:
read -d^ TEXT
#quit on ^
echo $NUMMER >> $TMPF
echo $TEXT >> $TMPF
mv $TMPF /var/spool/sms/outgoing/
else
exit
fi
 
'bash' Syntax Highlight powered by GeSHi


I think the code is very selfexplaining,
if not, let me know...

here is how i make the script talking over the network:

tcpserver <IP.ADD.DRE.SS> <PORT#> /path/to/script.sh

cheers
Ronny

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Thanks.

In what environment you have tested this script?

It did not work under Ubuntu GNU/Linux. Some minor changes were required: variable names are case sensitive (nummer vs. NUMMER), destination number must be in the same line with "To: ", and there must be single empty line between header lines and the message body.

The modified script could be:



Have you checked the script sendsms, located in the scripts directory of a package? That script can also be used with tcpserver, but it has no password protection by default.

Member
Registered:
Apr 2010
Location: Germany
Topic owner
damn...

sorry, i posted a preversion
and didnt doublecheck it :(

but generally the way should be clear...

the tcpserver testing was done in ubuntu lucid.
i'll try it this week on a debian, which will be the productive system.


be aware, i used the german word for number NUMMER for the ECHO , just if it confused someone...

hm, no i didnt recognize sendsms would work with tcpserver,
but i think any kind of passwordprotection should be used...


i got another script in progress,
which will do:
sms forwarding to (defined) groups via sms
sms forwarding to emailaddresses via shortname-email-matchfile
valid/invalid sender number (black/whitelist)
logging

but... perhaps you will tell me, everything of that is already onboard? ;)
sry, but i'm not yet so deep into sms server tools...

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
buster wrote
but generally the way should be clear...

the tcpserver testing was done in ubuntu lucid.
i'll try it this week on a debian, which will be the productive system.

Yes, it's clear, and surely tcpserver will run successfully on Debian too.

buster wrote
be aware, i used the german word for number NUMMER for the ECHO , just if it confused someone...

Not confused ;), but notice that case sensitivity. Shell script does not show any errors when names are typed differently.

buster wrote
hm, no i didnt recognize sendsms would work with tcpserver,
but i think any kind of passwordprotection should be used...

Yes, and protection could be useful for local usage too. Here is a new sendsms script which can use keys, one or more:



buster wrote
i got another script in progress,
which will do:
sms forwarding to (defined) groups via sms
sms forwarding to emailaddresses via shortname-email-matchfile
valid/invalid sender number (black/whitelist)
logging

but... perhaps you will tell me, everything of that is already onboard? ;)

If you are going to forward incoming messages, this all can be done with an eventhandler script. But as far as I remember here is no complete script published with all of those features.

Outgoing messages can be handled using the checkhandler. For example, some ToGroup: header can be used and the script could check it and write message files with To: <number> header, as many files as necessary.

Feel free to publish you innovations.

Member
Registered:
Apr 2010
Location: Germany
Topic owner
here we go...



Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Comments still welcome? ;)

Anyway...

You are running this script by a cron (or manually). Have you thought that this functionality could be done in the eventhandler script, which means that as soon as the SMS is received, forwarding is done?

When handling incoming files outside of the smsd, it is possible that the file is not yet complete when the script reads it. This is rare, but should still be considered. For example, when the smsd is reading outgoing files, it will check the size, and if it is not changed after one second, the file is handled as a complete file.

I recommend to change the handling of headers and message body of the message file. You are reading a header "Length" as a last header, but it's not always the last, for example when store_incoming_pdu setting is used. In the future versions there can also be another headers. As the format of SMS file is "e-mail format", the command formail could be used for handling of headers. This command is available in the procmail package. Here are three functions which I use for handling with the bash shell:



The message body of a file can also be extracted using the formail, but it will contain extra linefeed in the begin of a text. It can be removed with MESSAGEBODY=`formail -I "" < $FILENAME | sed -e"1d"`, but this command also works (without formail): MESSAGEBODY=`sed -e '1,/^$/ d' < $FILENAME`.

Instead of removing old headers, you can just write new headers, single empty line and $MESSAGEBODY to the new file, or if sending as an e-mail, just echo -n $MESSAGEBODY | ....

Generally taken your script may work, I have not tested it, but I think that it will fail if a SMS message is "Report: OK, Houston, we've had a problem here.".

Member
Registered:
Apr 2010
Location: Germany
Topic owner
Quote
Comments still welcome? ;)

yes, still welcome :)

indeed in the moment its running by cronjob,
but as soon as i read more about eventhandles i wanted to change that...

thanks for all the hints so far,
i will try to get it into the script as good as i can ;)

Quote
but I think that it will fail if a SMS message is "Report: OK, Houston, we've had a problem here.".

hm... why do you think so?

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
buster wrote
but as soon as i read more about eventhandles i wanted to change that...

Ok. This forum contains lot of samples, try this search.

buster wrote
Quote
but I think that it will fail if a SMS message is "Report: OK, Houston, we've had a problem here.".

hm... why do you think so?

Because you are grepping whole file, not just a header part. If some line in the message body starts with "Report:" (or with any defined header word), the whole line is dropped...

Member
Registered:
Apr 2010
Location: Germany
Topic owner
first of all:
thanks to keke for the hints!!

now with ~60 lines less




« Last edit by keke on Fri Apr 30, 2010 16:31, 172 months ago. »
Member
Registered:
Apr 2010
Location: Germany
Topic owner
this line

TEXT=`echo $TEXT | sed 's/ADMIN //'

should be

TEXT=`echo $TEXT | sed 's/^ADMIN //'

(isnt there a edit button?)

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
buster wrote
(isnt there a edit button?)

For members there is a time window (5 minutes) for editing after posting... ;)


You have not told what OS you are using and what is the version of smsd. In the help/support forum the posting will ask those details, but here in samples those details were not asked.

Your script is using the sh shell. In many cases that is a link to the bash shell, but not always and not on every platforms. I have not checked the syntax of your script, but in many samples the syntax of bash shell is used because it's much more powerful. If you copy some features from the sample scripts, you should use the bash.

Member
Registered:
Apr 2010
Location: Germany
Topic owner
i'm using debian lenny for that,
and smsd 3.1.6.
usually i had bash instead of sh there ;)
nevertheless, it works...

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.