Mac Script to count how long before Bluetooth becomes visible - linux

I'm trying to speed up a process on a linux machine. The end result of this operation is a bluetooth that then turns on.
I want to be able to run a script on my Mac than counts how long it takes before a bluetooth device name (that I provide to it) becomes visible.
Can someone please guide me to how I would go about this?
Scenario
On my linux machine I start some process that ends with the bluetooth to turn on.
At the same time, on my Mac, I press "enter" which starts counting until a bluetooth by the name "TEST_DEVICE" becomes available, at which put the system will spit out the time.

Related

is it possible to make PC or Linux machine shutdown for certain time and then make it come up again automatically?

I want to know if there is any way we can make either Windows or Linux machine shut down for let's say "N" minutes. and then it powers up automatically at the end of "N" minutes.
I know we can switch between OS using Grub from Linux and using third party software on Windows but never heard of such software or command to make it shut-down for certain time.
Check your BIOS, sometimes motherboards have a "boot at specific time" option in there if it's a regular thing
If you machine doesn't need to be fully off, then you could also hibernate. rtcwake is popular, allows disk-written low power hibernation and can be set to come back up automatically
Lastly if you need (or want, for energy reasons) it to be for reals off, and you don't have a timer boot option, most motherboards allow "Wake on LAN" or "Power by Eth" or something along those lines. Keeps enough power going to the network card to detect a broadcast packet with a wakeup signal matching your machine's
NIC's MAC address from the network, even when the computer has properly shutdown. This is my favourite method because it's true remote boot, but it means you need to have another device on the network.
There are readily available phone apps which can send a wake signal, I've only ever used manual ones but there's bound to be one on a timer. For linux I know there's ethtool and wakeonlan available, (haven't used either personally though.) Worst case scenario, there are several tutorials for baking your own, and the protocol isn't complex.
For Windows:
To my understanding you need to create a new task on the Windows Task Scheduler and let that task run after N minutes. The scheduler will program the BIOS' "power up on time" feature to the specified time. If the machine is powered (plugged in to wallsocket) and Windows is only in standby or hibernate mode (that is, not shut down), it should power up on the given time.
You might want to set the waking time about a minute early or so, since booting takes time as well. Also make sure energy saving options are not set too strict like "go to standby after X minuted of idle time" and this is in the middle of the unattended task execution ;)
I used this a lot when programming my PC to record from my TV card on a specific date and time and it worked well. DVBViewer handled all of the task creating stuff. I never set them up manually. There surely are other tools to automate the task creation if needed.
The manual way is something like this:
Right click on the Windows Start Button, select "Computer Administration Console" (or similar, I don't know the correct english naming), then a window pops up where you can right click in the tree view on the left handside on the item "Task Scheduler" (again, naming may differ) and select "Create simple Task" or "New Task..." (more advanced options). Hope you can manage from there.
Should work on Windows 7 to 10. Maybe earlier versions as well, but you need to figure out how to get to the task creation wizard.
Hope this helps, good luck :)

Check if USB device is idling, LINUX

I've got a quick question, but I can't find an answer.
Is it possible in linux (or in python) to see if an external usb pen drive is idling?
I need to know this for a python script I'm writing.
I need to rename a folder on an external usb pen drive as soon as nothing is writing to it.
edit: I know there is lsof command to list open files. 'lsof /theDir' only works half. It works OK when the process copying to the USB is still running. But when the process stops, lsof shows nothing. But the OS is still writing to the USB from its buffer.
You can check if all I/O has been processed by having a look at /sys/block/<dev>/stat.
The ninth column contains the number of I/Os currently in flight. Check https://www.kernel.org/doc/Documentation/block/stat.txt
Once this numner is zero the device should be idle.
To force all buffers to be written immediately you could execute sync and wait until it returns.
Nevertheless be aware that you have a race condition here if you are not controlling the writing - after you decided that the device is idle some other process could start writing to it.

Map stdin from second keyboard to a specific program / tty

I have a program (a bash script actually - console only) that scans or makes copies, etc based on user input. It asks questions such as how many copies would you like to make, etc and then scans the document, and prints it to another printer. The program runs in a loop so it's always there when a user passes by, and using a keyboard or number pad you can easily operate it. It basically makes a simple scanner/printer combo into a complex multifunction device.
I can leave it running on a dedicated system just fine, but to save electricity and resources, I would love to have it run on a computer someone else is already using. There is a user who has a laptop on the same desk as the scanner, and I was wanting to have her be able to do her thing in Xorg, as per usual, but have this little program running on an external monitor. That part is easy, but separating input is not. First of all the window has to be in focus, and then any input from the laptop keyboard OR usb keyboard is sent to the program, obviously.
I can think of one way to do this: using virtualbox, I can run a virtual machine without X, have it permanently ssh into the host OS (to which the usb scanner is connected) and I have virtualbox grab the usb keyboard input. But that seems excessive.
Does anyone know of a way to map input from a specific keyboard to a specific program or tty?

Is it possible to send SysRq commands with a barcode scanner?

We have a kiosk application that runs matchbox on top of linux, and has only a barcode scanner for input (no keyboard). It would be great to be able to print a barcode that--when scanned--sent commands like SysRq R etc, so that one could REISUB without having to disassemble the unit.
If there is not an existing way, could you patch the barcode driver to interpret a certain set of symbols and initiate the sequence?
Why do you need SysRq? Is the machine actually wedging itself or are you just trying to reboot cleanly? Why not just put a "reboot" command into whatever protocol you're using? What's wrong with simply doing a hard power cycle?

Fast Way To Check Many Bluetooth Devices by MAC Address

I'm creating a tool that checks for the presence of many (~100) bluetooth devices. I'll have their MAC addresses already. I just want to know if they're in range, even if not set to discoverable.
Using hcitool name <bt_addr> does this. But it's not very fast; it takes up to 5 seconds to check each address, especially if the device is not in range. If I fork parallel subprocesses, it still takes up to 5 seconds each, as if bluez or something in the stack is serializing the requests.
Is there a faster way to check for the presence of BT devices by MAC address? I don't need to know the names of them, just if they're around (whether set discoverable or not). Ideally I'd like to check all ~100 in half a minute or less.
Bonus points if the solution doesn't require sudo (like l2ping), but OK if that's the only way. Platform is Ubuntu Linux, using a Cambridge Silicon BT dongle if it matters...
Thanx,
-- Steve
No
If the device is not discoverable then there is no fast and effecting way.
Any other scheme (including requesting the name) requires establishing a connection - which will take few seconds each, there is no way the connection process can be done in parallel at the radio - it is one at a time.

Resources