Results 1 to 3 of 3

Thread: Test for BT pairing in bash

  1. #1
    Join Date
    Oct 2010
    Location
    Dayton, Ohio
    Beans
    75
    Distro
    Ubuntu 10.04 Lucid Lynx

    Test for BT pairing in bash

    This is probably something stupid, but...

    I want to test whether or not my phone is connected from bash. I'm finding lots of information about /dev/rfcomm0, but that's not on my system (Ubuntu 10.04). The device pairs just fine, and I can connect with gammu just fine, and I have the device address ("00:1F:5D:37:17:FB").

    I just need something I can put in a bash script to say "Is this connected or not" akin to testing for a file's existence:

    Code:
    if [ -f /home/steven/arbitrary filename ]
      then
        notify-send --icon=blueman "We're connected"
    fi
    Is there something simple like that?

    (Note: My phone's old enough that gammu's daemon doesn't work properly with it, which is why I'm hacking it this way.)
    I inject people with radioactive stuff for a living. But only to serve the forces of good.
    webpage | blog

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,790
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Test for BT pairing in bash

    -f tests for a regular file (neither a device or a directory). Try -e to check if something's just there.

    I hope it helps
    Last edited by papibe; December 23rd, 2010 at 09:26 PM. Reason: spelling

  3. #3
    Join Date
    Oct 2010
    Location
    Dayton, Ohio
    Beans
    75
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Test for BT pairing in bash

    The best thing I've found so far is to use hcitool - but I'm having a bit of a problem in my bash script:

    [code]
    isconnected=`hcitool inq ##:##:##:##:##:## | grep ##:##:##:##:##:##`
    echo $isconnected
    is_digit=`test "$isconnected" > "00"`
    if [ $is_digit -ne 1 ];
    then
    #dostuff
    fi
    [code]

    Obviously, that's the BT address of my phone. It correctly assigns $isconnected, but I can't get it to enter the loop properly. ::sigh::
    I inject people with radioactive stuff for a living. But only to serve the forces of good.
    webpage | blog

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •