Power Button Script

69 views
Skip to first unread message

bremenpl

unread,
Oct 2, 2014, 11:03:23 AM10/2/14
to beagl...@googlegroups.com
Hello there,
I am using Console version of debian provided on elinux.org on BeagleBone Black. My problem is that it misses the power button functionality. I have found this script for handling it:

#!/bin/sh

BTN
=/dev/input/event0

while true; do
  BTNVAL
=`hexdump -e '8/2 "%x " "\n"' -n 16 $BTN | grep ' 74 ' | awk '{print $7$
  if [ "$BTNVAL" = "1" ]
  then
    echo "Power button pressed"
    /sbin/sync
    /sbin/sync
    /sbin/shutdown -h now
    exit
  fi
  sleep 1
done


I have put a link to it into init.d and used update-rc to make it work at startup.
The problem is that it doesnt always work. Im not sure either it is running in the background or not, because when i use ps command i dont see the script running and even though the power button works. So lets say every 3rd power up the power button doesnt work... Im not sure whats the case. I would also aprichiate if someone told me either this is the proper way of handling the power button in the official bigger image.

bremenpl

unread,
Oct 2, 2014, 11:09:35 AM10/2/14
to beagl...@googlegroups.com
Also I forgot to mention, that in the script I actually have to put the line /sbin/shutdown -h now twice... Otherwise after I press the button the message that the system is going down is displayed, but the system is not turning off. Then I press it again and its going down.

Don deJuan

unread,
Oct 2, 2014, 12:28:53 PM10/2/14
to beagl...@googlegroups.com
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

There is problems with the script, not sure if it was a bad paste or not.

Look at your BTNVAL

Bremenpl

unread,
Oct 2, 2014, 12:46:54 PM10/2/14
to beagl...@googlegroups.com
Yes it was a bad pase, here is the script (unles you meant something else):


#!/bin/sh

BTN=/dev/input/event0

while true; do
  BTNVAL=`hexdump -e '8/2 "%x " "\n"' -n 16 $BTN | grep ' 74 ' | awk '{print $7}'`

  if [ "$BTNVAL" = "1" ]
  then
    echo "Power button pressed"
    /sbin/sync
    /sbin/sync
    /sbin/shutdown -h now
    /sbin/shutdown -h now
    exit
  fi
  sleep 1
done

W dniu 2014-10-02 18:28, Don deJuan pisze:
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/MAJFbngAJLA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

-- 
Bremenpl
Reply all
Reply to author
Forward
0 new messages