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"
|
echo "`date` - Checking Active Programs"
|
||||||
|
|
||||||
ps -ef | grep battery_nag.sh | grep -v grep
|
PID="$$"
|
||||||
active="$?"
|
ps -ef | grep battery_nag.sh | grep -v $$ | grep -v grep
|
||||||
if [[ "$active" == 0 ]]; then
|
|
||||||
echo "Program already running, exiting."
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "`date` - Loading Functions"
|
echo "`date` - Loading Functions"
|
||||||
|
|
||||||
which battery.function
|
which battery.function || {
|
||||||
|
echo "ERROR: Battery function not found, exiting."
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
source battery.function
|
source battery.function
|
||||||
|
|
||||||
echo "`date` - Parsing Parameters"
|
echo "`date` - Parsing Parameters"
|
||||||
@@ -49,6 +54,11 @@ while true; do
|
|||||||
title="Battery is below ${alert}%!"
|
title="Battery is below ${alert}%!"
|
||||||
message="Currently at ${batt}%."
|
message="Currently at ${batt}%."
|
||||||
cmd="`which fyi 2>/dev/null || which notify-send 2>/dev/null`"
|
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"
|
$cmd "$title" "$message"
|
||||||
status="$?"
|
status="$?"
|
||||||
@@ -77,6 +87,9 @@ while true; do
|
|||||||
echo "Battery under 10, 2x speed."
|
echo "Battery under 10, 2x speed."
|
||||||
time=$(( sleep / 2 ))
|
time=$(( sleep / 2 ))
|
||||||
fi
|
fi
|
||||||
|
if (( time < 10 )); then
|
||||||
|
time=10
|
||||||
|
fi
|
||||||
echo "`date` - Sleeping for ${time}"
|
echo "`date` - Sleeping for ${time}"
|
||||||
sleep $time
|
sleep $time
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user