I am trying to write a script to monitor some battery statuses on a laptop running as a server. To accomplish this, I have already started to write this code:
#! /bin/bash
# A script to monitor battery statuses and send out email notifications
#take care of looping the script
for (( ; ; ))
do
#First, we check to see if the battery is present...
if(cat /proc/acpi/battery/BAT0/state | grep 'present: *' == present: yes)
{
#Code to execute if battery IS present
#No script needed for our
application
#you may add scripts to run
}
else
{
#if the battery IS NOT present, run this code
sendemail -f
[email protected] -t 214*******@txt.att.net -u NTA TV Alert -m "The battery from the computer is either missing, or removed. Please check ASAP." -s smtp.gmail.com -o tls=yes -xu
[email protected] -xp ***********
}
#Second, we check into the current state of the battery
if(cat /proc/acpi/battery/BAT0/state | grep 'charging state: *' == 'charging state: charging')
{
#Code to execute if battery is charging
sendemail -f
[email protected] -t 214*******@txt.att.net -u NTA TV Alert -m "The battery from the computer is charging. This MIGHT mean that something just happened" -s smtp.gmail.com -o tls=yes -xu
[email protected] -xp ***********
}
#If it isn't charging, is it discharging?
else if(cat /proc/acpi/battery/BAT0/state | grep 'charging state: *' == 'charging state: discharging')
{
#Code to run if the battery is discharging
sendemail -f
[email protected] -t 214*******@txt.att.net -u NTA TV Alert -m "The battery from the computer is discharging. This shouldn't be happening. Please check ASAP." -s smtp.gmail.com -o tls=yes -xu
[email protected] -xp ***********
}
#If it isn't charging or discharging, is it charged?
else if(cat /proc/acpi/battery/BAT0/state | grep 'charging state: *' == 'charging state: charged')
{
#Code to run if battery is charged
}
done
I'm pretty sure that most of the other stuff works correctly, but I haven't been able to try it because it will not run. whenever I try and run the script, this is the
error that I get:
./BatMon.sh: line 15: syntax
error near unexpected token `}'
./BatMon.sh: ` }'
is the
error something super simple like a forgotten semicolon?
Thanks
-Tab00