You are not logged in.

#1 2010-06-08 06:51:57

bgalakazam
Arch Linux f@h Team Member
From: California, USA
Registered: 2008-09-01
Posts: 76

[solved] rc.d script "status" command

So I am trying to make a hotkey Fn+F6 to turn on and off my bluetooth. The problem is that ThinkWiki gives a script for init.d which have the status option. Without it, the action script only disables bluetooth as it never gets the status output string to check if it should enable or disable. This is not a major issue, however, I would like to get this working. Is there any other way to check if bluetooth is currently running and start/stop it all from 1 script?

The one they have is:

#!/bin/bash
# Bluetooth enable/disable script

/etc/init.d/bluetooth status

if [ "$?" -ne 0 ]; then
        /etc/init.d/bluetooth start > /dev/null
        echo enabled > /proc/acpi/ibm/bluetooth
        echo "Bluetooth enabled"
else
        /etc/init.d/bluetooth stop > /dev/null
        echo disabled > /proc/acpi/ibm/bluetooth
        echo "Bluetooth disabled"
fi

And the event controller is (not that it matters):

event=ibm/hotkey HKEY 00000080 00001006
action=/etc/acpi/actions/bluetooth

Last edited by bgalakazam (2010-06-09 23:42:37)

Offline

#2 2010-06-08 06:57:46

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,390
Website

Re: [solved] rc.d script "status" command

"ls /var/run/daemons" gives a list of currently running daemons, provided they are launched in the standard Arch way

Offline

#3 2010-06-08 08:08:44

bgalakazam
Arch Linux f@h Team Member
From: California, USA
Registered: 2008-09-01
Posts: 76

Re: [solved] rc.d script "status" command

So how would the if statement change then?

Offline

#4 2010-06-08 08:16:58

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,390
Website

Re: [solved] rc.d script "status" command

if [ -f /var/run/daemons/bluetooth ]

and you will want to change all those /etc/init.d/...

Offline

#5 2010-06-08 08:32:41

bgalakazam
Arch Linux f@h Team Member
From: California, USA
Registered: 2008-09-01
Posts: 76

Re: [solved] rc.d script "status" command

Right now my action script is:

#!/bin/bash
# Bluetooth enable/disable script

if [ -f /var/run/daemons/bluetooth ]; then
        /etc/rc.d/bluetooth stop > /dev/null
        echo disabled > /proc/acpi/ibm/bluetooth
        echo "Bluetooth disabled"
else
        /etc/rc.d/bluetooth start > /dev/null
        echo enabled > /proc/acpi/ibm/bluetooth
        echo "Bluetooth enabled"
fi

I have tried changing the if and else functions, but to no avail. I am also restarting acpid so it is not that.

Any ideas?

Offline

#6 2010-06-08 09:18:40

patroclo7
Member
From: Bassano del Grappa, ITALY
Registered: 2006-01-11
Posts: 915

Re: [solved] rc.d script "status" command

Are you running the script as root, aren't you?


Mortuus in anima, curam gero cutis

Offline

#7 2010-06-08 09:50:23

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: [solved] rc.d script "status" command

Why not use one of the already existing control files?
BT=/proc/acpi/ibm/bluetooth
BT=/sys/devices/platform/thinkpad_acpi/bluetooth_enable
BTCAT=$(grep -c "status.*enabled" /proc/acpi/ibm/bluetooth)
BTCAT=$(cat /sys/devices/platform/thinkpad_acpi/bluetooth_enable)

case "$BTCAT" in
  1) /etc/rc.d/bluetooth stop >/dev/null 2>&1
      echo 0 > $BT (or echo disabled > $BT, depending on the control file you choose)
  ;;
  0) ...
  ;;
esac

Maybe you should also introduce a test if the bluetooth daemon is running:
BTDAEMON=$(ls /var/run/daemons | grep -c bluetooth)
[[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
[[ $BTDAEMON = 0 ]] && /etc/rc.d/bluetooth start

As you're using a thinkpad, you can also use that on a hotkey:

#!/bin/sh
# /etc/acpi/handler.sh
BT=/sys/devices/platform/thinkpad_acpi/bluetooth_enable
BTCAT=$(cat $BT)
BTDAEMON=$(ls /var/run/daemons | grep -c bluetooth)
EVENT=$1\ $2\ $3\ $4

case "$EVENT" in
     ibm*1006)    # FN+F6
        case "$BTCAT" in
            1)    [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
                  echo 0 > $BT;;
            0)    [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth start
                  echo 1 > $BT;;
        esac;;
esac

Regards,
demian

Last edited by demian (2010-06-08 09:54:27)


no place like /home
github

Offline

Board footer

Powered by FluxBB