bash 在华为调制解调器上接收和回复短信,gammu-smsd:进程失败,退出状态为 2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19157763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:09:38  来源:igfitidea点击:

Recieve and reply to sms on huawei modem, gammu-smsd: Process failed with exit status 2

bashunicodesmsmodemgammu

提问by Mattis Asp

I Have a Huawei E220 HSDPA Modem on linux xubuntu I wanted to recieve sms and reply automatically to the sender. I Use gammu and Gammu-smsd to do this.

我在 linux xubuntu 上有一个华为 E220 HSDPA 调制解调器我想接收短信并自动回复发件人。我使用 gammu 和 Gammu-smsd 来做到这一点。

To automatically send sms back I added runOnRecieve = /path/to/bash/file into the /etc/gammu-smsdrc configuration-file.

为了自动发回短信,我将 runOnRecieve = /path/to/bash/file 添加到 /etc/gammu-smsdrc 配置文件中。

Here is the script:

这是脚本:

#!/bin/bash
str=$SMS_1_TEXT //string containing text from sender
tlf=$SMS_1_NUMBER //containing number from sender
tlf=${tlf:3}


if test "$str" = "today"; then

   echo "[Weather for today in Norway]
   Sol, noe overskyet
   [Vind fra s?r?st]
   Ha en fin dag!" | gammu-smsd-inject TEXT $tlf -unicode -autolen 200
else
   echo "fail" >> /home/mattis/sms.txt
fi

This is how I start the daemon

这就是我启动守护进程的方式

$ sudo gammu-smsd

This works if I run the bash script from terminal using test-input, but when the program gammu-smsd calls the script I get.

如果我使用 test-input 从终端运行 bash 脚本,这会起作用,但是当程序 gammu-smsd 调用我得到的脚本时。

gammu-smsd[3183]: Process failed with exit status 2

Now i can remove "gammu-smsd-inject" from the code and replace with "gammu sendsms" , but that would just give me gibberish letters instead of "??? and [ ]" when received back to the mobile.

现在我可以从代码中删除 "gammu-smsd-inject" 并替换为 "gammu sentms" ,但这只会在收到回手机时给我乱码而不是 "??? 和 [ ]"。

Hoping for positive answers.

希望得到积极的答复。

回答by Mattis Asp

--//--Working code--//--

--/ / --工作代码--/ /--

The thing is: Gammu sms inject acctually sends data to mysql database called smsd.

事情是:Gammu sms 注入实际上将数据发送到名为 smsd 的 mysql 数据库。

Creating this database:This should be created as specified in wammu sql database. Storing the SQL script for creating tables in MySQL database will able you to import it with phpmyadmin(gui) or any other way to interface mysql.

创建此数据库:这应该按照wammu sql database 中的指定创建。存储用于在 MySQL 数据库中创建表的 SQL 脚本将使您能够使用 phpmyadmin(gui) 或任何其他方式来连接 mysql。

Run on recieveAdd to the end of /etc/gammu-smsdrc --configuration file for gammu

Run on recieve添加到 /etc/gammu-smsdrc --gammu 的配置文件的末尾

runOnRecieve = /path/to/bash/file

Open the /path/to/bash/file

打开/path/to/bash/file

#!/bin/bash
str=$SMS_1_TEXT //codeword "weather"
tlf=$SMS_1_NUMBER //+47 41412424
tlf=${tlf:3} //remove +47

if test "$tlf" = "41412424"; then
    toSend = "[Weather for today in Norway]"
else
    toSend = "[you are not part of this group]"
    echo "Someone outside the group send to this number" > /home/user/activity.txt
fi

mysql --host=localhost --user=username --password=pw smsd << EOF
INSERT INTO outbox (
   DestinationNumber,
   TextDecoded,
   CreatorID,
   RelativeValidity
) VALUES (
   '$tlf',
   '$toSend',
   'Program',
   '255'
);
EOF

Start the daemon

启动守护进程

$ sudo gammu-smsd

That should be it!

应该是这样!

Extra tips:

额外提示:

  • Use $ gammu-detectto find out where the device is connected. Look for name = Phone on USB serial port HUAWEI_Technology HUAWEI_Mobileor something similar. Put this info in the configfile.
  • Be shure to add right permission to the bashfile. Make it readable to user running gammu-smsd.
  • Make the bashfile executable using chmod u+x /path/to/bash/file.
  • The gammu-smsd-monitor can be used to check how good signal you have. Be shure not to stop running the gammu-smsd when trying to run this.
  • You can test the bashfile by running it with dummy tlf and dummytext as input. $ ./bashfile.sh.
  • 使用$ gammu-detect找出设备连接的位置。寻找name = Phone on USB serial port HUAWEI_Technology HUAWEI_Mobile或类似的东西。将此信息放在配置文件中。
  • 务必为 bashfile 添加正确的权限。使其对运行 gammu-smsd 的用户可读。
  • 使用 chmod u+x /path/to/bash/file 使 bashfile 可执行。
  • gammu-smsd-monitor 可用于检查您的信号有多好。尝试运行此程序时,请务必不要停止运行 gammu-smsd。
  • 您可以通过使用 dummy tlf 和 dummytext 作为输入运行它来测试 bashfile。$ ./bashfile.sh.