ser2net에 대한 텔넷 세션을 실행하기 위한 쉘 스크립트

ser2net에 대한 텔넷 세션을 실행하기 위한 쉘 스크립트

VM(Debian 7.5)을 호스팅하기 위해 xenserver(무료)를 설정했습니다. 이 xenserver에는 직렬 GSM 모뎀을 연결했습니다. ser2net을 실행하도록 xen을 구성했으므로 직렬 에이전트를 사용할 수 있습니다. 이는 로컬 및 원격(텔넷) 모두에서 완벽하게 작동합니다. 이제 Debian VM에서 zenoss를 실행하고 있으며 페이징 기능을 사용하고 싶습니다. 텔넷 세션을 시뮬레이트하고 메시지를 보내는 bash 스크립트를 만들고 있습니다. 이 스크립트는 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
#...

스크립트를 실행합니다:

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

CtrlZ보내기를 시작하기 위해 제어 문자 +를 보내는 데 문제가 있어 중단됩니다 .(참고: ^Z는 vi가 삽입한 실제 문자입니다)또한 여러 명의 수신자를 어떻게 처리해야 합니까? 종료하고 연결을 끊으려면 어떻게 해야 합니까?

편집 : 나는 노력했다

"$메시지^Z"를 보냅니다.

도착하다

"$메시지"^Z를 보냅니다;

그러나 다음 결과를 얻습니다.

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)

고쳐 쓰다:

#!/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

Expect에서 제어 문자를 보내려면 8진수 문자를 보내세요.

send $message
send \032

또는

set ctrlZ \032
send "$message$ctrlZ"

인용하다:

관련 정보