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 

1 Answer 1

0

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

send $message send \032 

or

set ctrlZ \032 send "$message$ctrlZ" 

Ref:

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.