Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple script to turn on/off systemd-resolved.service from /etc/openvpn/update-resolv-conf.
#!/usr/bin/env bash
STATUS="$(sudo systemctl status systemd-resolved.service)"
# Stops the service if systemd-resolv.service is running.
if echo "${STATUS}" | grep -q "running"
then
sudo systemctl stop systemd-resolved.service > /dev/null 2>&1
if sudo systemctl status systemd-resolved.service | grep -q "inactive"
then
echo -e "\e[44mThe systemd-resolved.service has been stopped.\e[0m" && exit 0
else
echo -e "\e[41mThe service is still running.\e[0m" && exit 1
fi
fi
# Starts the service if systemd-resolv.service is not running.
if echo "${STATUS}" | grep -q "inactive"
then
sudo systemctl start systemd-resolved.service > /dev/null 2>&1
if sudo systemctl status systemd-resolved.service | grep -q "running"
then
echo -e "\e[42mThe systemd-resolved.service has been launched.\e[0m" && exit 0
else
echo -e "\e[41mThe service is still inactive.\e[0m" && exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment