2 ###############################################################################
4 # SENDSMS -- Script to send sms by 'gnokii'
5 # Author : Gabriele Zappi - Rimini <gzappi@inwind.it>
7 # feb 17, 2001 Script created (v1.0)
8 ###############################################################################
10 ###############################################################################
11 ###############################################################################
12 # PROGNAME=`basename $0`
22 BACKTITLE="SENDSMS V$VERSION"
23 AUTHOR="Gabriele Zappi - Rimini <gzappi@inwind.it>"
26 echo "$PROGNAME: $BACKTITLE - A gnokii interface for sending SMS."
27 echo "Written by $AUTHOR"
31 Usage: $PROGNAME [OPTION]...\n\
34 $PROGNAME # simply run $PROGNAME in standard mode\n\
35 $PROGNAME --simulate # Simulates. doesn't really send sms (for debug)\n\
36 echo \"Hello Beauty ;-)\" | $PROGNAME --smsset\n\
37 # Preset \"Hello Beauty ;-)\" as SMS message.\n\
38 $PROGNAME --smsset < mymessage.txt\n\
39 # Preset contents of file mymessage.txt \n\
41 $PROGNAME --version # Display version, author and quits.\n\
44 If you require to pickup number from phone's memory (really from SIM card),\n\
45 for the first time, it anyway reads phonebook from your cellular phone. \n\
46 (It may take a while... please, be patient ;-) \n\
49 --debug, -D May bother with more debugging messages ;-)\n\
50 For debugging purpose.\n\
51 --simul[ate], -S Simulation mode. Doesn't really send SMS by phone. \n\
52 Only simulates. For debugging purpose.\n\
53 --forcememread, -F Forces $PROGNAME to read phonebook from SIM card,\n\
54 and to parse the generated file in order to update\n\
55 the numbers' list (useful only if required to pickup\n\
56 number from the phone's memory). see NOTE.\n\
57 --skipgnokiicheck, -K Skip the test of the presence of binary 'gnokii'.\n\
58 (It must be somewhere in your \$PATH). It allows you\n\
59 to try this script program, even if you don't have\n\
60 'gnokii' already. ;)\n\
61 --smsset, --setsms Allows you to preset a SMS message from STDIN. (pipe\n\
62 or input redirection).\n\
63 This message will be proposed on the 'SMS message'\n\
64 field during the program input cycle.\n\
65 --help, -h, /h display this help and exit\n\
66 --version, -V output version information and exit"
73 rm -rf $TMP >/dev/null 2>&1
79 # Switch initialization
95 echo "$BACKTITLE - A gnokii interface for sending SMS."
96 echo "Written by $AUTHOR"
110 --skipgnokiicheck|-K)
113 --smsset|--msgset|--setsms)
115 # will read from stdin
116 echo "reading sms from stdin .."
120 echo "$PROGNAME: Invalid parameter: "
129 dialog --backtitle "$BACKTITLE" \
130 --yesno "Really sure to quit? " 6 50
131 if [ $? -eq 0 ]; then
137 dialog --backtitle "$BACKTITLE" --infobox "Reading phonebook by phone's SIM\n Please wait" 4 40
138 $GNOKII --getmemory SM 1 130 > $SMSDIR/.SMlist.temp
141 SMS_choicefrommem() {
142 # read from phonebook.
143 if [ "$SW_FORCEMREAD" = "yes" ] ; then
145 elif [ -s $SMSDIR/.SMlist.sim ]; then
146 dialog --backtitle "INSERT NUMBER(s).." \
147 --yesno "A SIM phonebook file is already present. \
148 Do you want to read phone memory anyway?" 8 60
149 if [ $? -eq 0 ] ; then
159 if [ $readsim -eq 1 ] ; then
161 if [ $? -ne 0 ] ; then
162 dialog --backtitle "INSERT NUMBER(s).." \
163 --msgbox "ERROR during reading memory from your phone... \
164 Insert manually destination number." 8 60
167 mv -f $SMSDIR/.SMlist.temp $SMSDIR/.SMlist.sim
171 if [ $ERROR -eq 0 ]; then
172 # Parsing sim file...
173 if [ ! -s $SMSDIR/.SMlist.chklst -o ! -s $SMSDIR/.SMlist.choice \
174 -o $readsim -eq 1 ] ; then
175 > $SMSDIR/.SMlist.menu
176 > $SMSDIR/.SMlist.chklst
177 > $SMSDIR/.SMlist.choice
178 totrows=`cat $SMSDIR/.SMlist.sim | wc -l`
182 rownow=`expr $rownow + 1`
183 perc=`expr $rownow \* 100 / $totrows`
184 pos=`echo $riga | cut -f4 -d";"`
185 name=`echo $riga | cut -f1 -d";"`
186 num=`echo $riga | cut -f2 -d";"`
187 if [ -n "$pos" -a -n "$num" ] ; then
188 echo -e "$pos \"$name - $num\"" >> $SMSDIR/.SMlist.menu
189 echo -e "$pos \"$name - $num\" off" >> $SMSDIR/.SMlist.chklst
190 echo "$pos;$num" >> $SMSDIR/.SMlist.choice
193 done < $SMSDIR/.SMlist.sim) | dialog \
194 --gauge "Parsing phonebook file..." 12 70 0
199 while [ $chkok -eq 0 ]
201 eval dialog --backtitle \"SENDSM CKECKLIST\" \
202 --checklist \"Check your MEMORY number\(s\).\
203 \\nPress ESC key \for options..... \" \
205 `cat $SMSDIR/.SMlist.chklst` 2> $TMP/rspTEMP02
207 if [ $option -eq 255 ] ; then
208 dialog --backtitle "SENDSM CKECKLIST" --menu \
209 "Options sub-menus for Phonebook choise list:" \
211 "1" "Sort by Memory Pos" \
212 "2" "Sort by Names" \
213 "9" "Quit $PROGNAME" 2> $TMP/rspTEMP04
214 if [ $? -eq 0 ]; then
215 sorttype=`cat $TMP/rspTEMP04`
217 1) sort -n $SMSDIR/.SMlist.chklst > $TMP/.SMlist.tmp
218 mv -f $TMP/.SMlist.tmp $SMSDIR/.SMlist.chklst
220 2) sort +1 $SMSDIR/.SMlist.chklst > $TMP/.SMlist.tmp
221 mv -f $TMP/.SMlist.tmp $SMSDIR/.SMlist.chklst
232 if [ $? -eq 0 ] ; then
233 for val in `cat $TMP/rspTEMP02`
235 tok1=`eval echo $val`
236 tok2=`grep "^$tok1;" $SMSDIR/.SMlist.choice`
237 tok3=`echo $tok2 | cut -f2 -d";"`
238 if [ -z "$NUMBERS" ] ; then
241 NUMBERS="$NUMBERS $tok3"
248 ###########################################################################
249 ###########################################################################
251 ###########################################################################
252 ###########################################################################
256 # This is the 'help' test...
257 # if [ "$1" = "--help" -o "$1" = "/h" ] ; then
261 if ! type -all "dialog" >/dev/null 2>&1 ; then
263 echo "${PROGNAME}: error:"
264 echo "Can't find 'dialog', i can't run without 'dialog' on your system."
265 echo "You can get a compiled elf version of 'dialog' from here."
266 echo "http://www.tux.org/pub/people/kent-robotti/index.html"
267 echo "ftp://ftp.tux.org/pub/people/kent-robotti 'dialog-0.9a-15.elf.tar.gz'"
272 if [ $SW_SKIPGNOKITST = no ] ; then
273 if ! type -all "$GNOKII" >/dev/null 2>&1 ; then
275 echo "${PROGNAME}: error:"
276 echo "Can't find 'gnokii'. This script needs 'gnokii' in order to work."
277 echo "You can get a version of 'gnokii' from following links:"
278 echo "GNOKII: http://multivac.fatburen.org/gnokii/ , http://www.gnokii.org/"
280 echo " Pavel Janik (who is to thank for a vast part of the 6110 development) "
281 echo "also keeps an ftp archive of some recent things."
283 echo "Source code and pre-compiled binaries for gnokii are available from "
284 echo "a number of sites"
286 echo "ftp.gnokii.org located in California, USA"
287 echo "linuxcare.com.au located in Canberra, Australia"
288 echo "multivac.fatburen.org located in Stockholm, Sweden "
290 echo "Pre release versions are kept here, maintained by Pawel Kot"
291 echo "urtica.linuxnews.pl located in Warsaw, Poland"
293 echo "MYGNOKII (can handle other newer Nokia models...)"
295 echo "Marcin Wiacek -> mailto:marcin-wiacek@topnet.pl"
296 echo "http://marcin-wiacek.topnet.pl (http://www.fkn.pl/marcinw) -> netmonitor,"
297 echo "firmware, mygnokii (GSM & Nokia)"
298 echo "http://grumble.zereau.com/gnokii/ &"
299 echo "http://www.mds.mdh.se/~cel95eig/mygnokii/ -> mygnokii mirrors"
305 if [ ! -d ~/tmp ]; then
310 if [ ! -d $SMSDIR ]; then
322 echo "$BACKTITLE" > $TMP/txtTEMP01
323 echo >> $TMP/txtTEMP01
324 echo "Written by Gabriele Zappi <gzappi@inwind.it> " >> $TMP/txtTEMP01
325 echo >> $TMP/txtTEMP01
326 echo "This script is a front-end to type SMS messages directly" >> $TMP/txtTEMP01
327 echo "from your computer and send them using gnokii through" >> $TMP/txtTEMP01
328 echo "your cellular phone connected to your computer." >> $TMP/txtTEMP01
329 echo >> $TMP/txtTEMP01
330 echo "Press [Enter] to continue with SENDSMS." >> $TMP/txtTEMP01
332 dialog --backtitle "$BACKTITLE" --textbox "$TMP/txtTEMP01" 14 70
337 echo "Please, enter in the box below, your SMS message." > $TMP/txtTEMP$$
338 echo "Remember that it cannot be longer than 160 chars." >> $TMP/txtTEMP$$
339 echo " " >> $TMP/txtTEMP$$
340 echo "Press [ESC] or [CANCEL] to quit the program. " >> $TMP/txtTEMP$$
343 if [ $TURN -eq 0 ]; then
344 if [ "$SW_PRESETSMS" = "yes" ]; then
345 echo "$PRESETSMS" > $TMP/rspTEMP01
350 while test "$len" -le 0 -o "$len" -gt 160
352 dialog --backtitle "INSERT SMS ....." \
353 --inputbox "`cat $TMP/txtTEMP$$`" 10 70 "`cat $TMP/rspTEMP01`" \
355 if [ $? -ne 0 ] ; then
358 len=`cat $TMP/rspTEMP01 | wc -c `
360 if [ $len -le 0 -o $len -gt 160 ] ; then
361 echo "Invalid SMS: It must be < 160 chars and > 0 long.." > $TMP/txtTEMP02
362 dialog --textbox "$TMP/txtTEMP02" 6 70
368 while [ "$NUMBERS" = "" -o "$okcycle" -eq 0 ]
370 dialog --backtitle "INSERT NUMBER(s).." \
371 --yesno "would you like to pick up number(s) \
372 from your phone memory" 8 60
375 if [ $? -eq 0 ] ; then # Yes, gimme num from phonebook.
379 # Manual telephone number completion or insertion.
380 echo "Please, insert/modify in the box below, the NUMBER(S)" > $TMP/txtTEMP$$
381 echo "where you want to send the message to. " >> $TMP/txtTEMP$$
382 echo "(Multiple numbers must be separated by a space.) " >> $TMP/txtTEMP$$
383 echo "Press [ESC] or [CANCEL] to quit the program. " >> $TMP/txtTEMP$$
384 echo " " >> $TMP/txtTEMP$$
385 echo "OUTGOING MESSAGE: " >> $TMP/txtTEMP$$
387 cat $TMP/rspTEMP01 | cut -c1-60 >> $TMP/txtTEMP$$
388 cat $TMP/rspTEMP01 | cut -c61-120 >> $TMP/txtTEMP$$
389 cat $TMP/rspTEMP01 | cut -c121-160 >> $TMP/txtTEMP$$
392 dialog --backtitle "INSERT NUMBER(s).." \
393 --inputbox "`cat $TMP/txtTEMP$$`" \
394 16 70 "$NUMBERS" 2> $TMP/rspTEMP03
396 if [ $? -ne 0 ] ; then
400 NUMBERS=`cat $TMP/rspTEMP03`
401 if [ "$NUMBERS" = "" ] ; then
402 dialog --backtitle "INSERT NUMBER(s).." \
403 --infobox "Number cannot be empty.\n Try again.." 4 28
410 # Last confirmation before sending messages....
413 while [ $okcycle -eq 0 ]
415 echo "Ok. If you confirm the operation, the the SMS" > $TMP/txtTEMP$$
416 echo "is going to be sent to the selected number(s)." >> $TMP/txtTEMP$$
417 echo >> $TMP/txtTEMP$$
418 echo "Press [ESC] to quit the program. " >> $TMP/txtTEMP$$
419 echo "Press [CANCEL] to return to SMS input. " >> $TMP/txtTEMP$$
420 dialog --backtitle "$BACKTITLE" \
421 --yesno "`cat $TMP/txtTEMP$$`" 9 60
426 TURN=`expr $TURN + 1`
432 TURN=`expr $TURN + 1`
436 # echo "Sending sms to number $num ... "
437 dialog --backtitle "$BACKTITLE" --infobox "Sending sms to number $num ...\n Please wait" 4 45
438 if [ "$SW_SIMUL" = "yes" ] ; then
441 $GNOKII --sendsms $num < $TMP/rspTEMP01 > /dev/null 2>&1
443 if [ $? -eq 0 ] ; then
444 dialog --backtitle "$BACKTITLE" \
445 --infobox "Message correctly sent to number $num !" 3 55
447 dialog --backtitle "$BACKTITLE" \
448 --infobox "Sent Failed to num $num! Sorry!" 3 55