我创建了一个脚本,希望通过蓝牙发送文件。 为此,我使用了“ 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]#
结果应该与在终端上手动执行或使用脚本自动执行的结果相同。
有人可以提供我在做错事情的建议。