mario.oshiro
(usa Ubuntu)
Enviado em 14/07/2009 - 15:38h
# ./enviarsms.sh '01122222222|tim|txt|Teste de Envio'
toUpper() {
echo $1 | tr "[:lower:]" "[:upper:]"
}
ret=`echo $1 | sed 's/|/\n/g' | wc -l`
if [ $ret -lt 4 ]
then
echo "./enviarsms.sh '01181113842|tim|txt|Teste de Envio'"
echo "./enviarsms.sh '01181113842|claro|pdu|Texto em BCD'"
exit 1
fi
rm -f saida.txt
echo $1 | sed 's/|/ /g' | while read fone oper tipo texto
do
tipo=`toUpper $tipo`
oper=`toUpper $oper`
tty=`grep $oper smsped.conf | cut -f2`
if [ "$tty" = "" ]
then
tty=`grep DEFAULT smsped.conf | cut -f2`
fi
if [ "$tty" = "" ]
then
exit 2
fi
echo "send atz\r\n" > sms.scr
echo "expect {" >> sms.scr
echo "\"OK\" goto CMGF" >> sms.scr
echo "timeout 20 goto FIM" >> sms.scr
echo "}" >> sms.scr
echo "CMGF:" >> sms.scr
if [ "$tipo" = "PDU" ] >> sms.scr
then
echo "send at+cmgf=0\r\n" >> sms.scr
else
echo "send at+cmgf=1\r\n" >> sms.scr
fi
echo "expect {" >> sms.scr
echo "\"ERROR\" goto FIM" >> sms.scr
echo "\"OK\" goto CMGS" >> sms.scr
echo "timeout 10 goto FIM" >> sms.scr
echo "}" >> sms.scr
echo "CMGS:" >> sms.scr
echo "send at+cmgs="$fone"\r\n" >> sms.scr
echo "expect {" >> sms.scr
echo "\"ERROR\" goto FIM" >> sms.scr
echo "\">\" goto SIGA" >> sms.scr
echo "timeout 10 goto FIM" >> sms.scr
echo "}" >> sms.scr
echo "SIGA:" >> sms.scr
echo "send "$texto >> sms.scr
echo "send \{TTEXTO}32" >> sms.scr
echo "expect {" >> sms.scr
echo "\"ERROR\" goto FIM" >> sms.scr
echo "\"+CMGS\" goto SUCESSO" >> sms.scr
echo "\"OK\" goto SUCESSO" >> sms.scr
echo "timeout 20 goto FIM" >> sms.scr
echo "}" >> sms.scr
echo "SUCESSO:" >> sms.scr
echo "print SU,CE,SS,O" >> sms.scr
echo "FIM:" >> sms.scr
echo "! killall -9 minicom" >> sms.scr
minicom -S sms.scr > saida.txt
done
ret=`grep SU,CE,SS,O saida.txt 2>/dev/null | wc -l`
if [ $ret -eq 1 ]
then
exit 0
else
exit 1
fi