From 91816bedf8af5bdfbff9677354892421ff0b9fee Mon Sep 17 00:00:00 2001 From: Martin Berghaus Date: Sun, 23 Feb 2025 09:00:17 +0100 Subject: [PATCH] revised addToCrontabEveryHour --- core/addToCrontabEveryHour.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/addToCrontabEveryHour.sh b/core/addToCrontabEveryHour.sh index 3635750..89c5f47 100755 --- a/core/addToCrontabEveryHour.sh +++ b/core/addToCrontabEveryHour.sh @@ -5,14 +5,18 @@ +# Folders always ends with an tailing '/' +_SCRIPT="$(readlink -f "${0}" 2> /dev/null)" +_CORE_SCRIPTS="$(dirname ${_SCRIPT:?"Missing SCRIPT"} 2> /dev/null)/" +_CIS_ROOT="$(dirname ${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"} 2> /dev/null)/" + # Note that an unprivileged user can use this script successfully, # if no user has to be added to the host because it already exists. function addToCrontabEveryHour() { - local _CIS_ROOT _MINUTE_VALUE _STRING - _CIS_ROOT="${0%%/core/*}/" #Removes longest matching pattern '/core/*' from the end + local _MINUTE_VALUE _STRING ! [ -z "${2##*[!0-9]*}" ] && _MINUTE_VALUE=$((${2}%60)) # if second parameter is integer then (minute-value % 60) as safe guard _STRING="${_MINUTE_VALUE:?"Missing MINUTE_VALUE"} * * * * ${1:?"Missing first parameter COMMAND"} > /dev/null 2>&1" - readonly _CIS_ROOT _MINUTE_VALUE _STRING + readonly _MINUTE_VALUE _STRING [ "$(id -u)" == "0" ] \ && crontab -l | grep -qF "${_STRING:?"Missing CRON_STRING"}" \