#!/bin/bash # Script for sending long letters via SMS using "sms" program # Ver: 1.3 # Autor: Murphy # Date: 06/12/2000 # -------------------------------------------------------------------- # ^ e-mail: GaduGadu: #297149 ^ # ^ | ^ piotr@sonycom.com ^ | ^ # | | | murph@free.polbox.pl | | | # |/|\| murphy@pulstar.albedo.art.pl |/|\| # | | # | Everything is possible - this is only question of time | # -------------------------------------------------------------------- if [ "$#" -lt "2" ] || [ "$#" -gt "4" ]; then echo -e "SEND MESSAGE\n" echo -e "Scripts send SMS message using \"sms\" program\n" echo -e "Usage:" echo -e "\tsend_mesg [reverse] [sleeptime]\n" echo -e "reverse - send SMS in reverse order" echo -e "sleeptime - time beetwen send another sms part in seconds\n" echo -e "Example:" echo -e "\tsend_mesg 606324542 letter.txt" exit 1 fi case $# in 3) if [ "$3" == "reverse" ]; then export reverse=YES export rev_op="-1 -r" else export reverse=NO export rev_op="-1" if [ `echo $3 | tr -d "[:alpha:]" ""` ]; then export delay=$3 else export delay=0 fi fi ;; 4) if [ "$3" == "reverse" ]; then export reverse=YES export rev_op="-1 -r" else export reverse=NO export rev_op="-1" fi if [ `echo $4 | tr -d "[:alpha:]" ""` ]; then export delay=$3 else export delay=0 fi ;; esac if [ $3 ]; then export reverse=YES export rev_op="-1 -r" else export reverse=NO export rev_op="-1" fi umask 166 # Telephone operator recognition export direct=`echo $1 | awk '{printf("%.3s",$1)}'` case $direct in 602|604|606|608) #Set SMS limitation for ERA (150 char) export length=150 ;; 601|603|605) #Set SMS limitation for PLUS (1378 char) export length=1378 ;; 501) #Set SMS limitation for IDEA (633 char) export length=633 ;; esac if [ ! "$length" ]; then echo -e "Brak zdefiniowanego operatora!" echo -e "Dodaj nowy numer kierunkowy do zdefiniowanych lub nowy wraz" echo -e "z ograniczeniem długości wiadomości SMS" exit 2 fi # Count characters in message export num=`cat $2 | wc -m` # Calculate numbers of SMS export pieces=`echo "$num/$length" | bc` # Check for rest-partial SMS message, which have less size than "length" export rest=`echo "$num-$pieces*$length" | bc` # If if rest = increase pieces of SMS if [ $rest != 0 ]; then export pieces=`echo "$pieces+1"|bc` fi # Count number in $pieces variable export pie_num=`echo $pieces | wc -m` # Reserve some space for message numbering (3 characters for "(\)") export length=`echo "$length-3-2*${pie_num}" | bc` # Recalculate again number of SMS export pieces=`echo "$num/$length" | bc` # Check for rest-partial SMS message, which have less size than "length" export rest=`echo "$num-$pieces*$length" | bc` # If is rest - increase pieces of SMS if [ $rest != 0 ]; then export pieces=`echo "$pieces+1"|bc` fi # Split letter to smalest file split -b $length $2 $2. # Create unique name for temporary file export tmp=`date '+%d%m%y_%H%M%S'` echo -e "$USER ($pieces) messages to send" if [ "$reverse" == "YES" ]; then export count=$pieces else export count=1 fi # send all files using sms command for i in `/bin/ls ${rev_op} $2.??` do # Set error > 1 for go inside the "while" loop state=1 # Calculate length of $count co_len=`echo $count | wc -m` # if lenght of $count is less than $pie_num if [ "${co_len}" -lt "${pie_num}" ]; then # how much zero zero=`echo "${pie_num}-${co_len}" | bc` echo -n "(" > $tmp # Add nessessary number of zero's for (( x=0 ; x<$zero; x++ )); do echo -n "0" >> $tmp done echo -n "$count/$pieces)" >> $tmp else echo -n "($count/$pieces)" > $tmp fi cat $i >> $tmp # If some error occur during SMS transmission - send again while [ "$state" != "0" ]; do sms $1 < $tmp state=$? if [ "$state" != "0" ]; then echo -e "\tPart $count of $pieces sent again" fi # Delay between parts of message sleep $delay done rm $i echo -e "Part $count of $pieces sent" if [ "$reverse" == "YES" ]; then export count=`echo "$count-1"|bc` else export count=`echo "$count+1"|bc` fi done echo -e "\nAll SMS sent\n" # Remove temporary file rm $tmp