Correct log issues / permissions for MagicSPAM

269ac00f765508cb74b25d006dbf5bb2

Written by Dennis Nind

Last published at: February 8th, 2019
#!/bin/bash
# the user log directory needs the correct permissions and ownership
for LINE in $(getent passwd); do
    # retrieve the user name and user home directory
    USER_NAME=$(echo "$LINE" | cut -d':' -f1)
    USER_HOME_DIR=$(echo "$LINE" | cut -d':' -f6)

    # build path to user log directory
    USER_MS_LOG_DIR="$USER_HOME_DIR/magicspam/logs"

    # nothing to do when the user log directory does not exist
    if [ -d "$USER_MS_LOG_DIR" ]; then
        echo "Setting permission for user [$USER_NAME] with magicspam log directory [$USER_MS_LOG_DIR]"

        # set the permissions and ownership of the user log directory
        # NOTE: only the ownership gets set recursively on the directory
        chown -R magicspam:$USER_NAME $USER_MS_LOG_DIR
        chmod 2750 $USER_MS_LOG_DIR

        # ensure that the log files in the directory has the correct permissions
        find $USER_MS_LOG_DIR -type f -exec chmod 0640 '{}' \;
    fi
done