battery_nag, improve the active process checker and enhance edge case handling.
This commit is contained in:
@@ -4,16 +4,21 @@
|
||||
|
||||
echo "`date` - Checking Active Programs"
|
||||
|
||||
ps -ef | grep battery_nag.sh | grep -v grep
|
||||
active="$?"
|
||||
if [[ "$active" == 0 ]]; then
|
||||
echo "Program already running, exiting."
|
||||
PID="$$"
|
||||
ps -ef | grep battery_nag.sh | grep -v $$ | grep -v grep
|
||||
|
||||
active=`ps -ef | grep battery_nag.sh | grep -v $$ | grep -vc grep`
|
||||
if (( "$active" >= 1 )); then
|
||||
echo "Program already running, exiting. Number of processes: $active"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "`date` - Loading Functions"
|
||||
|
||||
which battery.function
|
||||
which battery.function || {
|
||||
echo "ERROR: Battery function not found, exiting."
|
||||
exit 2
|
||||
}
|
||||
source battery.function
|
||||
|
||||
echo "`date` - Parsing Parameters"
|
||||
@@ -49,6 +54,11 @@ while true; do
|
||||
title="Battery is below ${alert}%!"
|
||||
message="Currently at ${batt}%."
|
||||
cmd="`which fyi 2>/dev/null || which notify-send 2>/dev/null`"
|
||||
if [[ -z "$cmd" ]]; then
|
||||
echo "ERROR: No command found to send notification, exiting."
|
||||
echo "Please install 'fyi' or 'notify-send' to use this script."
|
||||
exit 3
|
||||
fi
|
||||
|
||||
$cmd "$title" "$message"
|
||||
status="$?"
|
||||
@@ -77,6 +87,9 @@ while true; do
|
||||
echo "Battery under 10, 2x speed."
|
||||
time=$(( sleep / 2 ))
|
||||
fi
|
||||
if (( time < 10 )); then
|
||||
time=10
|
||||
fi
|
||||
echo "`date` - Sleeping for ${time}"
|
||||
sleep $time
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user