我创建了一个脚本,我想通过蓝牙发送文件。为此,我使用了“obexctl”实用程序。我可以通过终端使用 obexctl 实用程序传输文件。但是当我尝试使用 expect 将其合并到脚本中时,它显示“客户端代理不可用”。
有人能帮我解决代码问题吗?提前谢谢了。
终端命令:
$ obexctl
[NEW] Client /org/bluez/obex
[obex]# connect xx:xx:xx:xx:xx:xx
Attempting to connect to xx:xx:xx:xx:xx:xx
[NEW] Session /org/bluez/obex/client/session11 [default]
[NEW] ObjectPush /org/bluez/obex/client/session11
Connection successful
[xx:xx:xx:xx:xx:xx]# send abc.txt
Attempting to send abc.txt to /org/bluez/obex/client/session3
[NEW] Transfer /org/bluez/obex/client/session3/transfer1
Transfer /org/bluez/obex/client/session3/transfer1
Status: queued
Name: filename.sh
size: 0
Filename: abc.txt
Session: org/bluez/obex/client/session3
[CHG] Transfer /org/bluez/obex/client/session3/transfer1 Status: complete
[DEL] Transfer /org/bluez/obex/client/session3/transfer1
[xx:xx:xx:xx:xx:xx]#
Shell 脚本:
#!/bin/bash
....
/usr/bin/expect << EOF
set prompt "#"
spawn sudo obexctl
#expect -re \$prompt
expect "Client"
send "connect $hw_addr\r"
sleep 4
expect "Connection"
send "send $bluetooth_log_file\r"
send "quit\r"
EOF
....
执行此脚本时,它会提供以下输出:
spawn sudo obexctl
[obex]# connect xx:xx:xx:xx:xx:xx
Client proxy not available
[obex]#
在终端上手动执行和使用脚本自动执行的结果应该相同。
有人能给我提出一些建议,指出我做错的地方吗?