File: sms2xml

package info (click to toggle)
smstools 3.1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,596 kB
  • ctags: 820
  • sloc: ansic: 14,175; sh: 1,173; php: 115; makefile: 44; awk: 17
file content (23 lines) | stat: -rwxr-xr-x 752 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh

#This script converts a received text message to XML.
#Written by Thomas Dolberg, October 2005

#run this script only when a message was received.
if [ "$1" != "RECEIVED" ]; then exit; fi;

#Extract data from the SMS file
FROM=`formail -zx From: < $2`
TEXT=`formail -I "" <$2 | sed -e"1d"`

#Save as XML
#for some reason the mktemp-command creates two instances of the file if I add the .xml-extension to the FILENAME-variable.
FILENAME=`mktemp /var/spool/sms/XML/answerXXXXXX`
echo "<?xml version='1.0'?>" >$FILENAME.xml
echo "<SMS>" >>$FILENAME.xml
echo "  <from>$FROM</from>" >>$FILENAME.xml
echo "  <message>$TEXT</message>" >>$FILENAME.xml
echo "</SMS>" >>$FILENAME.xml

#Delete the original file without the .xml-extension
rm $FILENAME