#!/usr/bin/expect --
#
if {[llength $argv] == 0} {
puts "usage : send_sms number message"
exit 1
}
#stty raw -echo
set CTRLZ \x1A
set CTRLD \x04
set telnet_host localhost
set telnet_port 23
set number_to_sms [lindex $argv 0]
set message_to_sms [lindex $argv 1]
puts "number_to_sms $number_to_sms\r"
puts "message_to_sms $message_to_sms\r"
set timeout 60
log_user 1
exp_internal 1
set spawn_id [spawn telnet $telnet_host $telnet_port]
expect "'^]'."
#this sets text mode"
send "at+cmgf=1\r"
expect "OK"
#this sets the destination number
send "at+cmgs=\"$number_to_sms\"\r"
expect "> "
#type the message and end with CTRL-Z (doesn't seem to work,send CTRL_Z
later)
exp_send "$message_to_sms\r"
expect -re "(\[^\r\n]*)\r\n"
#remove susp control code from tty ( otherwise CTRL-Z will suspend the
program)
stty susp ^-
set res [stty -a]
puts $res
#send CTRL-Z followed by CTRL-D to flush the buffer
exp_send "\x1A\x04"
expect "OK"
exit 0