Power Button Script

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.

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.

W dniu czwartek, 2 października 2014 17:03:23 UTC+2 użytkownik bremenpl napisał:

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

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