Re: [dev] Remount rootfs sync on impending battery depletion.

From: Gene Auyeung <quaker4lyf_AT_gmail.com>
Date: Sat, 4 Dec 2010 11:23:41 -0800

Hi,

Just curious, how would the script get permission to mount? You can't
type the password for sudo because it's not interactive. And you can't
rely on the limited time that sudo grants access if you run the script
with sudo, because presumably the battery lasts much longer than that?

Thanks,
Gene

On Sat, Dec 4, 2010 at 11:16 AM, Antoni Grzymala <antoni_AT_chopin.edu.pl> wrote:
> Hi,
>
> just wanted to share a simple idea here – a little feature implemented
> in my statusbar script: remount the rootfs sync, when the battery
> level is below some predefined threshold and falling.
>
> I somehow find it less distracting than warnings popping up and less
> annoying then a forced poweroff upon reaching some level.
>
> Here's my implementation (full of bash, gnu tools and other stuff you
> love), feel free to pick ideas if you find any of it useful:
>
> #!/bin/bash
>
> while test 1; do
>
> ############################################################
> # Battery charge.
>
> DO_BATTERY=""
> BATTERY=BAT0 ### <- Battery ID
>
> grep ' charged' /proc/acpi/battery/${BATTERY}/state 2>&1 >/dev/null && TIME_LEFT="" || DO_BATTERY=1
>
> if [[ -n ${DO_BATTERY} ]]; then
>  TIME_LEFT=`acpi | head -n1 | sed -r \
>  's/^.*Battery....//; s/discharging, /-/i; s/charging, /+/i; s/,//g; s/ ([0-9][0-9]:[0-9][0-9]):[0-9][0-9] .*$/ \1 /'`
>
>  if [[ "${TIME_LEFT}" =~ ^-[0-5]% ]]; then
>    TIME_LEFT="[fs SYNC] ${TIME_LEFT}"
>    grep '^/dev/root.*sync,' /proc/mounts || sudo mount / -o remount -o sync
>  else
>    grep '^/dev/root.*sync,' /proc/mounts && sudo mount / -o remount
>  fi
>
>  TIME_LEFT="${TIME_LEFT} · "
> fi
>
> ### [...much other code including some sleep...]
>
> STATUS="${TKABBER}${UNREADMAIL}${TIME_LEFT}${PPPD}${WIRELESS}${FETCHMAIL}${UPTIME}${DATE}"
> xsetroot -name "${STATUS}"
>
> done
>
> --
> [a]
>
>
Received on Sat Dec 04 2010 - 20:23:41 CET

This archive was generated by hypermail 2.2.0 : Sat Dec 04 2010 - 20:36:02 CET