Posted On December 13, 2020

Linux: Create a Shell Script to Watch Services

kimconnect 0 comments
blog.KimConnect.com >> Linux >> Linux: Create a Shell Script to Watch Services
# create a script to watch services (notice the regex escape for special chars)
sudo cat << EOF > /usr/local/sbin/watchservice
#!/bin/bash
service=\$@
/bin/systemctl -q is-active "\$service.service"
status=$?
if [ "\$status" == 0 ]; then
    echo "OK"
else
    /bin/systemctl start "\$service.service"
fi
EOF

# Mark the file with executable permissions
sudo chmod +x /usr/local/sbin/watchservice

# Create a new entry in cron
sudo crontab -e

# Ensure that services are running
* * * * * /usr/local/sbin/watchservice pihole-FTL > /dev/null

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Linux: How to set a static IP address

Set Static IP Address ---- vim /etc/sysconfig/networking/profiles/default/ifcfg-eth0 vim /etc/sysconfig/network-scripts/ifcfg-eth0 ---- DEVICE=eth0 BOOTPROTO=none HWADDR=00:0C:29:d7:5b:d3 ONBOOT=yes TYPE=Ethernet…

Installing Linux Kernel on Windows 10 Machines

# installLinuxOnWindows10.ps1 # Please don't try to run this on target OS Windoze XP or…

Ubuntu 18.04: Network Configuration Utility

Prior to version 18.04, network configurations have been via these commands: sudo vim /etc/network/interfaces sudo…