From 4e655ae8daddca0282e57cb6499c94af2e4fc7bb Mon Sep 17 00:00:00 2001 From: Bob Mottram <bob@freedombone.net> Date: Sun, 25 Feb 2018 15:16:23 +0000 Subject: [PATCH] Tidying cron utils --- src/freedombone-utils-cron | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/freedombone-utils-cron b/src/freedombone-utils-cron index 09b8237dd..a041acac3 100755 --- a/src/freedombone-utils-cron +++ b/src/freedombone-utils-cron @@ -31,7 +31,7 @@ function cron_add_mins { if ! grep -q "${2}" /etc/crontab; then job_user='root' - if [ $3 ]; then + if [ "$3" ]; then job_user=$3 fi echo "*/${1} * * * * ${job_user} ${2}" >> /etc/crontab @@ -48,29 +48,29 @@ function randomize_cron { fi # randomize the day on which the weekly cron job runs - randdow=$(($RANDOM%6+1)) - sed -i "s|\* \* 7|* * $randdow|g" /etc/crontab + randdow=$((RANDOM%6+1)) + sed -i "s|\\* \\* 7|* * $randdow|g" /etc/crontab # randomize the time when the weekly cron job runs - randmin=$(($RANDOM%60)) - randhr=$(($RANDOM%3+1)) + randmin=$((RANDOM%60)) + randhr=$((RANDOM%3+1)) sed -i "s|47 6|$randmin $randhr|g" /etc/crontab # randomize the time when the daily cron job runs - randmin=$(($RANDOM%60)) - randhr=$(($RANDOM%3+4)) - sed -i "s|25 6\t\* \* \*|$randmin $randhr\t* * *|g" /etc/crontab + randmin=$((RANDOM%60)) + randhr=$((RANDOM%3+4)) + sed -i "s|25 6\\t\\* \\* \\*|$randmin $randhr\\t* * *|g" /etc/crontab # randomize the time when the hourly cron job runs - randmin=$(($RANDOM%60)) - sed -i "s|17 \*\t|$randmin *\t|g" /etc/crontab + randmin=$((RANDOM%60)) + sed -i "s|17 \\*\\t|$randmin *\\t|g" /etc/crontab # randomize monthly cron job time and day - randmin=$(($RANDOM%60)) - randhr=$(($RANDOM%22+1)) - randdom=$(($RANDOM%27+1)) - sed -i "s|52 6\t|$randmin $randhr\t|g" /etc/crontab - sed -i "s|\t1 \* \*|\t$randdom * *|g" /etc/crontab + randmin=$((RANDOM%60)) + randhr=$((RANDOM%22+1)) + randdom=$((RANDOM%27+1)) + sed -i "s|52 6\\t|$randmin $randhr\\t|g" /etc/crontab + sed -i "s|\\t1 \\* \\*|\\t$randdom * *|g" /etc/crontab systemctl restart cron @@ -79,17 +79,17 @@ function randomize_cron { function schedule_stig_tests { stig_tests_script=/tmp/stig_tests_script - echo '#!/bin/bash' > $stig_tests_script - echo "ADMIN_EMAIL_ADDRESS=${MY_USERNAME}@\${HOSTNAME}" >> $stig_tests_script - echo "pkill ${PROJECT_NAME}-tests" >> $stig_tests_script - echo 'rm -rf /tmp/*' >> $stig_tests_script - echo "${PROJECT_NAME}-tests --stig yes > /tmp/daily-stig-tests" >> $stig_tests_script - echo 'if [ ! "$?" = "0" ]; then' >> $stig_tests_script - echo " echo \"\$(cat /tmp/daily-stig-tests)\" | mail -s \"${PROJECT_NAME} STIG test failures\" \$ADMIN_EMAIL_ADDRESS" >> $stig_tests_script - echo 'fi' >> $stig_tests_script - echo 'if [ -f /tmp/daily-stig-tests ]; then' >> $stig_tests_script - echo ' rm /tmp/daily-stig-tests' >> $stig_tests_script - echo 'fi' >> $stig_tests_script + { echo '#!/bin/bash'; + echo "ADMIN_EMAIL_ADDRESS=${MY_USERNAME}@\${HOSTNAME}"; + echo "pkill ${PROJECT_NAME}-tests"; + echo 'rm -rf /tmp/*'; + echo "${PROJECT_NAME}-tests --stig yes > /tmp/daily-stig-tests"; + echo 'if [ ! "$?" = "0" ]; then'; + echo " echo \"\$(cat /tmp/daily-stig-tests)\" | mail -s \"${PROJECT_NAME} STIG test failures\" \$ADMIN_EMAIL_ADDRESS"; + echo 'fi'; + echo 'if [ -f /tmp/daily-stig-tests ]; then'; + echo ' rm /tmp/daily-stig-tests'; + echo 'fi'; } > $stig_tests_script chmod +x $stig_tests_script if [ ! -f /etc/cron.daily/stig_tests ]; then -- GitLab