1

I have setup a xenserver (free) hosting a VM (Debian 7.5). On this xenserver I have attached a serial GSM modem. I have configured xen to run ser2net so I have a serial proxy available. This works perfectly local and remote (telnet). Now on the Debian VM I am running zenoss and I wish to use the paging functionality. I'm creating a bash script to simulate the telnet session and sending a message. This script is only working for 50%.

#!/usr/bin/expect
set timeout 20
set number [lindex $argv 0]
set message [lindex $argv 1]
spawn telnet 10.10.0.52 3333
#wait?
sleep 1
send AT+CMGS="$number"\r;
expect ">"
send "$message^Z";
interact
#...

Running the script:

administrator@debian:/home/zenoss$ ./sms.sh +32486000000 xxen
spawn telnet 10.10.0.52 3333
Trying 10.10.0.52...
Connected to 10.10.0.52.
Escape character is '^]'.
AT+CMGS="+32486000000"
> xxen^Z

I'm having problems sending the control character Ctrl+Z to initiate the send, it hangs. (note: the ^Z is the real character inserted with vi) Plus how should I go about multiple recipients? And how should I exit and disconnect.

EDIT: I tried

send "$message^Z";

to

send "$message"^Z;

but got this result:

administrator@debian:/home/zenoss$ ./sms.sh +32486000000 xxen
spawn telnet 10.10.0.52 3333
Trying 10.10.0.52...
Connected to 10.10.0.52.
Escape character is '^]'.
AT+CMGS="+32486000000"
> extra characters after close-quote
    while executing
"send "$message"^Z;
interact
#...
"
    (file "./sms.sh" line 10)

UPDATE:

#!/usr/bin/expect
# - VAR
set ctrlz \032
set xt \135
set timeout 15
set host [lindex $argv 0]
set port [lindex $argv 1]
set number [lindex $argv 2]
set message [lindex $argv 3]
# - CONNECT
spawn telnet $host $port
sleep 1
# - SEND
send AT+CMGS="$number"\r;
expect ">"
send "$message$ctrlz";
expect "OK"
# - END
0

To send a control character in expect, send an octal character.

send $message
send \032

or

set ctrlZ \032
send "$message$ctrlZ"

Ref:

  • Do you know how I could log all output from within the script? – grmbl May 26 '14 at 9:05
  • You want the log_file command – glenn jackman May 26 '14 at 16:30
  • tried that but I only get log entries when I run the script manually... – grmbl May 27 '14 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.