0

I am running hcitool application ($hcitool lescan). It detects all the bluetooth connected devices and shows the UUID for each. I press Ctrl+C when I see sensortag UUID B0:B4:48:BD:0F:83 and proceed. I want all this to be done using a .sh script. Please guide.

  • http://stackoverflow.com/questions/5789642/how-to-send-controlc-from-a-bash-script – AlecTMH Nov 26 '15 at 11:29
  • 1
    What have you tried until now? -- Sending the equivalent of a Ctrl+C from a script would be done with `kill -INT $pid`, where $pid is the process you want to send the signal to. – Hellmar Becker Nov 26 '15 at 11:29
  • Clearly an xy question http://xyproblem.info/ , don't take it literally... Consider rephrasing the question. What do you want to happen? – Karoly Horvath Nov 26 '15 at 11:31
  • I want to stop sensing for more devices once it detects the required one. I had tried bkill tilll now which didnt work, –  Nov 26 '15 at 11:44
  • How can I see the process ID. I tried giving kill -INT but not sure of the PID. –  Nov 26 '15 at 23:57

2 Answers2

2

grep can quit immediately when a pattern is found:

hcitool lescan | grep -q 'B0:B4:48:BD:0F:83'
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
0

kill -INT process_ID

CTRL + C sends a SIGINT signal. kill also does the same. So, just pass the process ID to the above command.

To get the PID(process ID) type command : pgrep foo(suppose foo is your process)

  • Grepping for processes is generally a bad idea, what if there are two or more processes running? Surely you don't want to kill someone else's process.... – Karoly Horvath Nov 26 '15 at 11:40