#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/crons/08-cron-daily.txt ################################## #### path: /var/www/crons/08-cron-daily ############################################################ #### destination: n/a (not a boilerplate) ########################################################## #### purpose: SlickStack core cron job *daily* (08/13) will run every 1 day ######################## #### module version: Ubuntu 20.04 LTS ############################################################## #### sourced by: root crontab ###################################################################### #### bash aliases: ss cron daily ################################################################### #################################################################################################### ## 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 #################################################################################################### #### 08-Cron-Daily: Ensure SS-Check + SS-Worker (Core Bash Scripts) Intact ######################### #################################################################################################### ## 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 ## FILE_SS_CHECK="/var/www/ss-check" STRING_SS_CHECK="SS_EOF" if [[ ! -f "$FILE_SS_CHECK" ]] || [[ -z $(grep -q "$STRING_SS_CHECK" "$FILE_SS_CHECK") ]]; then rm /tmp/ss-check* wget -O /tmp/ss-check http://mirrors.slickstack.io/ss-check.txt cp /tmp/ss-check /var/www/ss-check cp /tmp/ss-check /var/www/bash/ss-check chown root:root /var/www/ss-check ## must be root:root chown root:root /var/www/bash/ss-check ## must be root:root chmod 0700 /var/www/ss-check ## 0700 means root can execute chmod 0700 /var/www/bash/ss-check ## 0700 means root can execute rm /tmp/ss-check* fi ## ensure ss-worker exists and intact ## FILE_SS_WORKER="/var/www/ss-worker" STRING_SS_WORKER="SS_EOF" if [[ ! -f "$FILE_SS_WORKER" ]] || [[ -z $(grep -q "$STRING_SS_WORKER" "$FILE_SS_WORKER") ]]; then rm /tmp/ss-worker* wget -O /tmp/ss-worker http://mirrors.slickstack.io/ss-worker.txt cp /tmp/ss-worker /var/www/ss-worker cp /tmp/ss-worker /var/www/bash/ss-worker chown root:root /var/www/ss-worker ## must be root:root chown root:root /var/www/bash/ss-worker ## must be root:root chmod 0700 /var/www/ss-worker ## 0700 means root can execute chmod 0700 /var/www/bash/ss-worker ## 0700 means root can execute rm /tmp/ss-worker* fi #################################################################################################### #### 08-Cron-Daily: 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_DAILY" ]]; then echo "$SS_CUSTOM_CRON_DAILY" fi ## run wp-cron if set to daily ## if [[ "$WP_CRON_METHOD" == "server" ]] && [[ "$WP_CRON_INTERVAL" == "daily" ]]; then /usr/bin/php /var/www/html/wp-cron.php fi ## run ss-dump-database if set to daily ## if [[ "$SS_INTERVAL_DUMP_DATABASE" == "daily" ]]; then source /var/www/ss-dump-database fi ## run ss-clean-files if set to daily ## if [[ "$SS_INTERVAL_CLEAN_FILES" == "daily" ]]; then source /var/www/ss-clean-files fi ## run ss-install-wordpress-config if set to daily ## if [[ "$SS_INTERVAL_INSTALL_WORDPRESS_CONFIG" == "daily" ]]; then source /var/www/ss-install-wordpress-config fi ## run ss-sync-staging if set to daily ## if [[ "$SS_INTERVAL_SYNC_STAGING" == "daily" ]]; then source /var/www/ss-sync-staging fi ## run ss-install-wordpress-mu-plugins if set to daily or if not defined (default) ## if [[ "$SS_INTERVAL_INSTALL_WORDPRESS_MU_PLUGINS" == "daily" || -z "$SS_INTERVAL_INSTALL_WORDPRESS_MU_PLUGINS" ]]; then source /var/www/ss-install-wordpress-mu-plugins fi ## run ss-perms if set to daily ## if [[ "$SS_INTERVAL_PERMS" == "daily" ]]; then source /var/www/ss-perms fi ## run ss-dos2unix if set to daily ## if [[ "$SS_INTERVAL_DOS2UNIX" == "daily" ]]; then source /var/www/ss-dos2unix fi ## run ss-scan-malware if set to daily ## if [[ "$SS_INTERVAL_SCAN_MALWARE" == "daily" ]]; then source /var/www/ss-scan-malware fi ## run ss-optimize-database if set to daily ## if [[ "$SS_INTERVAL_OPTIMIZE_DATABASE" == "daily" ]]; then source /var/www/ss-optimize-database fi ## run ss-purge if set to daily ## if [[ "$SS_INTERVAL_PURGE" == "daily" ]]; then source /var/www/ss-purge fi ## run ss-install-ubuntu-crontab if set to daily ## if [[ "$SS_INTERVAL_INSTALL_UBUNTU_CRONTAB" == "daily" ]]; then source /var/www/ss-install-ubuntu-crontab fi ## run ss-install-ubuntu-bash if set to daily ## if [[ "$SS_INTERVAL_INSTALL_UBUNTU_BASH" == "daily" ]]; then source /var/www/ss-install-ubuntu-bash fi #################################################################################################### #### 08-Cron-Daily: 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 #################################################################################################### #### 08-Cron-Daily: 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/08-cron-daily*.lock* #################################################################################################### #### 08-Cron-Daily: 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-08-cron-daily #################################################################################################### #### 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