在Shell脚本中使用AT命令 [英] Use AT command in shell script
问题描述
我正在使用gsm调制解调器通过终端发送短信,没有问题,但是我想编写一个shell脚本(由php调用),并且我想知道如何在其中插入AT命令.
I'm using gsm modem to send sms, via a terminal there's no problem but i want to write a shell script (called by php) and i want to know how insert AT command in.
示例:
- 调用脚本.sh
- 脚本打开minicom(sudo ..)
- 类型:AT + CMGS ="num" + ENTER +消息" + ctrl + Z 并将短信发送到号码.
- call the script.sh
- the script open minicom (sudo..)
- type : AT+CMGS="num" + ENTER + "Message" + ctrl+Z and send the sms to the num.
谢谢 维克多
推荐答案
For the time being1 I think your best option here is to use the programming language expect. It is written to monitor growing text output and support scenarios like
- 等待字符串
"Username:"
出现在输出中. - 发送字符串
"my_name"
. - 等待字符串
"Password:"
出现在输出中. - 发送字符串
"my_secret_password"
.
- Wait for the string
"Username:"
to appear in the output. - Send the string
"my_name"
. - Wait for the string
"Password:"
to appear in the output. - Send the string
"my_secret_password"
.
发送AT命令并等待响应非常相似,因此这是绝对可行的.当我在爱立信工作时,我们编写了一个测试套件,期望它可以发送AT命令并解析日志文件以运行测试.
Sending AT command and waiting for the response is very similar, so this is absolutely doable. When I worked at Ericsson we had a test suite written in expect that sent AT commands and parsed log files to run tests.
1 作为我的 atinout 程序的伴侣,我已经开始编写一个程序来发送命令AT + CMGS及其有效载荷正确.但是除非您非常非常有耐心,否则您不应该等待此操作完成.
1 As a companion to my atinout program, I have started to write a program to send the command AT+CMGS and its payload correctly. But unless you are very, very patient you should not wait for this to be finished.
这篇关于在Shell脚本中使用AT命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!