As you might have noticed the “hcitool lescan” command doesn’t have a timeout argument. This limitation makes the Bluetooth Low Energy scan last forever until a CTRL+C breaks the execution.
To be able to scan for Bluetooth Low Energy devices in range for a given period of time and store the output of the scan in a file I’ve created the following script (lescan.sh):
#!/bin/sh hciconfig hci0 down hciconfig hci0 up hcitool lescan > $2 & pid=$! sleep $1 kill -INT $pid wait $pid