#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/crons/05-cron-hourly.txt ################################# #### path: /var/www/crons/05-cron-hourly ########################################################### #### destination: n/a (not a boilerplate) ########################################################## #### purpose: SlickStack core cron job *hourly* (05/13) will run every 1 hour ###################### #### module version: Ubuntu 20.04 LTS ############################################################## #### sourced by: root crontab ###################################################################### #### bash aliases: ss cron hourly ################################################################## #################################################################################################### ## NEVER MODIFY THE ROOT CRONTAB AND SS CORE CRON JOBS OR YOUR STACK WILL STOP WORKING ## ## INSTEAD CUSTOMIZE SS_INTERVAL SETTINGS OR ADD CUSTOM JOBS IN YOUR SS-CONFIG ## ## include SlickStack configuration ## source /var/www/ss-config ## include SlickStack functions ## source /var/www/ss-functions #################################################################################################### #### 05-Cron-Hourly: Ensure SS-Check + SS-Worker Intact (Core Bash Scripts) ######################## #################################################################################################### ## SNIPPET: ss core cron jobs ## this improves redundancy by having ss core cron jobs ensure ss core bash scripts exist ## ## the root crontab in SlickStack likewise ensures that ss core cron jobs exist ## ## ensure ss-check exists and intact ## if [[ ! -f "$PATH_SS_CHECK" ]] || [[ -z $(grep -q "$SS_EOF" "$PATH_SS_CHECK") ]]; then rm /tmp/ss-check* wget -O /tmp/ss-check "$MIRROR_SS_CHECK" cp /tmp/ss-check /var/www/ss-check chown root:root /var/www/ss-check ## must be root:root chmod 0700 /var/www/ss-check ## 0700 means root can execute rm /tmp/ss-check* fi ## ensure ss-worker exists and intact ## if [[ ! -f "$PATH_SS_WORKER" ]] || [[ -z $(grep -q "$SS_EOF" "$PATH_SS_WORKER") ]]; then rm /tmp/ss-worker* wget -O /tmp/ss-worker "$MIRROR_SS_WORKER" cp /tmp/ss-worker /var/www/ss-worker chown root:root /var/www/ss-worker ## must be root:root chmod 0700 /var/www/ss-worker ## 0700 means root can execute rm /tmp/ss-worker* fi #################################################################################################### #### 05-Cron-Hourly: Run Scheduled Tasks ########################################################### #################################################################################################### ## the below tasks will be called if configured to run at this interval in ss-config ## ## certain tasks are automatically called if the relevant interval is missing ## ## run custom cron jobs ## if [[ -n "$SS_CUSTOM_CRON_HOURLY" ]]; then echo "$SS_CUSTOM_CRON_HOURLY" fi ## run wp-cron if set to hourly ## if [[ "$WP_CRON_METHOD" == "server" ]] && [[ "$WP_CRON_INTERVAL" == "hourly" ]]; then /usr/bin/php /var/www/html/wp-cron.php fi ## run ss-check if set to hourly ## if [[ "$SS_INTERVAL_CHECK" == "hourly" ]]; then source /var/www/ss-check fi ## run ss-worker if set to hourly ## if [[ "$SS_INTERVAL_WORKER" == "hourly" ]]; then source /var/www/ss-worker fi ## run ss-dump-database if set to hourly or if not defined (default) ## if [[ "$SS_INTERVAL_DUMP_DATABASE" == "hourly" || -z "$SS_INTERVAL_DUMP_DATABASE" ]]; then source /var/www/ss-dump-database fi ## run ss-clean-files if set to hourly ## if [[ "$SS_INTERVAL_CLEAN_FILES" == "hourly" ]]; then source /var/www/ss-clean-files fi ## run ss-sync-staging if set to hourly ## if [[ "$SS_INTERVAL_SYNC_STAGING" == "hourly" ]]; then source /var/www/ss-sync-staging fi ## run ss-perms if set to hourly ## if [[ "$SS_INTERVAL_PERMS" == "hourly" ]]; then source /var/www/ss-perms fi #################################################################################################### #### 05-Cron-Hourly: Reset Permissions (SS Core Bash Scripts) ###################################### #################################################################################################### ## SNIPPET: ss core cron jobs ## we hardcode this permissions reset snippet into ss core cron jobs for redundancy ## ## chmod 700 means only the root/sudo users can execute ss core bash scripts ## ## reset permissions ## chown root:root /var/www/ss* ## must be root:root chmod 0700 /var/www/ss* ## 0700 means root can execute chown root:root /var/www/bash/ss* ## must be root:root chmod 0700 /var/www/bash/ss* ## 0700 means root can execute #################################################################################################### #### 05-Cron-Hourly: Delete Lock File ############################################################## #################################################################################################### ## here we delete the lock file associated with this cron job to clear the cron queue ## ## this is technically not necessary but we do it anyway for extra security ## ## delete lock file ## rm /tmp/05-cron-hourly*.lock* #################################################################################################### #### 05-Cron-Hourly: Touch Timestamp File (End Script) ############################################# #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## touch /var/www/meta/.timestamp-05-cron-hourly #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://bash.cyberciti.biz/guide/Setting_up_permissions_on_a_script ## Ref: https://stackoverflow.com/questions/22861580/bash-script-check-if-a-file-contains-a-specific-line ## Ref: https://stackoverflow.com/questions/4749330/how-to-test-if-string-exists-in-file-with-bash/14201583 ## Ref: https://stackoverflow.com/questions/11287861/how-to-check-if-a-file-contains-a-specific-string-using-bash ## Ref: https://stackoverflow.com/questions/4749330/how-to-test-if-string-exists-in-file-with-bash- ## Ref: https://stackoverflow.com/questions/42377739/while-file-doesnt-contain-string-bash ## SS_EOF