#!/bin/bash # Do an action if cert changed # do_action_if_cert_changed.sh # Urheber Ralph Hahn, Seif-Wald-Ring 26, 54329 Konz-Roscheid # This script is distributed in the hope that it will be useful, but without any guarantees; # without even the implied warranties of merchantability or fitness for a particular purpose. # See the GNU General Public License for more information. See file: license.txt - http://www.gnu.org/licenses/gpl.html # You can use and redistribute this file freely under the terms of the GNU General Public License. # You can make changes or customize. Caution: incorrect declarations can cause problems! # Always test individual changes immediately before making further ones. # # create folder sysadm in homes /volume1/homes/sysadm or any other you want # create folder do_action_if_cert_changed in sysadm /volume1/homes/sysadm/do_action_if_cert_changed # create folder log in sysadm/do_action_if_cert_changed /volume1/homes/sysadm/do_action_if_cert_changed/log # # save this script as /volume1/homes/sysadm/do_action_if_cert_changed/do_action_if_cert_changed.sh # # Set a task in task-scheduler: user root | every day | bash /volume1/homes/sysadm/do_action_if_cert_changed/do_action_if_cert_changed.sh # typeset -i FILEDATECERT FILEDATEDO CERTPATH="/usr/syno/etc/certificate/_archive/$(cat /usr/syno/etc/certificate/_archive/DEFAULT)" LOGFILE="/volume1/homes/sysadm/do_action_if_cert_changed/log/do_action_if_cert_changed_$(date '+%Y%m').log" LASTCHANGE="/volume1/homes/sysadm/do_action_if_cert_changed/do-lastchange" CERTFILE=$CERTPATH/fullchain.pem FILEDATECERT=$(date --reference=${CERTFILE} +%Y%m%d) if [ -f $LASTCHANGE ]; then FILEDATEDO=$(cat "$LASTCHANGE") else FILEDATEDO=0 fi if [[ ${FILEDATEDO} -ge ${FILEDATECERT} ]];then echo "${FILEDATEDO} ${FILEDATECERT} Nothing todo!" >> "$LOGFILE" exit fi # define your action here, set ACTION to anything if done # action begin # action end if [ -z "$ACTION" ] then echo "${FILEDATEDO} ${FILEDATECERT} do_action_if_cert_changed failed." >> "$LOGFILE" echo "0" > "$DOFILE" else echo "${FILEDATEDO} ${FILEDATECERT} do_action_if_cert_changed done." >> "$LOGFILE" echo $FILEDATECERT > "$LASTCHANGE" fi