I am writing expect script to run bluetoothctl commands. When the commands run successfully when bluetoothctl runs well. But if there is problem with bluetooth service it shows "Waiting to connect to bluetoothd..." and at this point the expect script exists. I want to catch that exception, restart the bluetooth service and then run the expect script again. Here is the script:
#!usr/bin/expect -f
set prompt "#"
set address [lindex $argv 0]
spawn sudo bluetoothctl
expect{
$prompt{
send "scan on\r"
sleep 5
send "scan off\r"
send "connect $address\r"
expect "Connection successful" {send "pair $address\r"}
expect "Pairing successful
}
timeout {
send_user "\n----------\r"
expect eof
}
}
I tried with using timeout but then whole script stops working after prompt appears.