#!/bin/bash # Rocky9 compatible . /usr/src/k_framework/main.sh # ---- VARS ----- SCRIPT_NAME="TmpWatch Cron Disable" VERSION="1.0.3" cron="/etc/cron.daily/tmpwatch" # ---- FUNCTIONS ----- # ---- MAIN ----- k_start k_detect_os if [[ $ROCKY9 == 1 ]]; then if ! [[ -f /etc/tmpfiles.d/tmp.conf ]]; then echo "v /tmp 1777 root root" >> /etc/tmpfiles.d/tmp.conf echo "v /var/tmp 1777 root root" >> /etc/tmpfiles.d/tmp.conf report "/etc/tmpfiles.d/tmp.conf config to NOT remove /tmp files has been created" 0 else report "/etc/tmpfiles.d/tmp.conf config already exists" 3 fi k_exit $EXIT_CODE fi if ((centos_version == 6)); then if [ -f /etc/cron.daily/tmpwatch ]; then rm -f "$cron" report "$cron cron was removed" 0 else report "$cron does not exist in system" 3 fi else # https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html # Files in /etc/tmpfiles.d override files with the same name in /usr/lib/tmpfiles.d and /run/tmpfiles.d. # Packages should install their configuration files in /usr/lib/tmpfiles.d. # Files in /etc/tmpfiles.d are reserved for the local administrator, who may use this logic to override the configuration files installed by vendor packages. # Default Centos 7 file /usr/lib/tmpfiles.d/tmp.conf contains these lines # v /tmp 1777 root root 10d # v /var/tmp 1777 root root 30d # So create file /etc/tmpfiles.d/tmp.conf with same content but without deleting part (10d and 30d) if ! [[ -f /etc/tmpfiles.d/tmp.conf ]]; then echo "v /tmp 1777 root root" >> /etc/tmpfiles.d/tmp.conf echo "v /var/tmp 1777 root root" >> /etc/tmpfiles.d/tmp.conf report "/etc/tmpfiles.d/tmp.conf config to NOT remove /tmp files has been created" 0 else report "/etc/tmpfiles.d/tmp.conf config already exists" 3 fi fi k_exit $EXIT_CODE