I am trying to write a bash script to set a variable "status" to either online or offline. I use logger "trigger offline" and logger "trigger online" for simplicity.
The offline event triggers ok, and I can see the output correct in journalctl, but when the online event is sent by logger, the variable £status is still offline. If its offine, I want it to restart the NetworkManger until the event online is triggered. thanks
!/bin/bash
journalctl -fqn0 | \
while read line
do
#trigger if offline
echo "$line" | grep "trigger offline"
if [ $? = 0 ]
then
status="offline"
fi
#trigger if online
echo "$line" | grep "trigger online"
if [ $? = 0 ]
then
status="online"
fi
sleep 3
logger "Status is $status"
if [[ $status="offline" ]]
then
#restart the network here
logger "do some stuff"
fi
done