Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Continuously monitor a systemd service
#!/bin/bash
cd /root/.maint
# Remove any pre-existing pipe if one exists
if [[ -e jcpipe ]]; then
rm -f jcpipe
fi
mkfifo jcpipe
# Use this command to feed the pipe with data continuously
/usr/bin/journalctl -x -b -f -u hostapd >jcpipe &
# Now read lines from the pipe forever; if we find the error message, take action.
while read line; do
if [[ "$line" =~ "Could not add STA to kernel driver" ]]; then
# wait 3s then restart
sleep 3
/usr/bin/systemctl restart hostapd
fi
done < jcpipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment