I'm trying do to a script to check the CA power status
this is my code:
#!/bin/bash
a=$(acpitool -a)
echo "$a"
if $a -eq "AC adapter : online"
then
echo "ONLINE"
else
echo "OFFLINE"
fi
It's not working; the variable $a ia not compare with the the string "AC adapter : online". How to convert the output of command acpitool -a to a string?
This is what happens:
AC adapter : online
./acpower.sh: linha 7: AC: comando não encontrado
OFFLINE
Problem solved!
This is the new code, whith the help of all of you, thanks.
#!/bin/bash
# set the variable
a=$(acpitool -a)
# remove white spaces
a=${a// /}
# echo for test
echo $a
# compare the result
if [[ "$a" == 'ACadapter:online' ]]
then
# then that the imagination is the limit
echo "ONLINE"
else
# else if you have no imagination you're lost
echo "OFFLINE"
fi
This code may be use on a server, to alert if the power fails!