Systemd service file

From Teknologisk videncenter
Revision as of 05:45, 17 April 2024 by Heth (talk | contribs) (Created page with "If i want a service daemon to log if my server is online every minute. The following procedure could be used: ==My service== <source lang=bash> #!/bin/bash # Filename: /usr/...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If i want a service daemon to log if my server is online every minute. The following procedure could be used:

My service

#!/bin/bash
# Filename: /usr/local/sbin/mysserver-online.sh
# Ownership: root:root 
# Permissions:  755 
IP="192.168.1.72"
LOGFILE="/tmp/myserver.log"

while :
do
        if ping -c 1 $IP > /dev/null 2>&1
        then
                echo "$(date) online" >> $LOGFILE
        else
                echo "$(date) OFFLINE" >> $LOGFILE
        fi
        sleep 60
done