Last active
August 16, 2017 09:07
-
-
Save mauricioprado00/9c0b696a2cf0aa88b55c82be86af6ee7 to your computer and use it in GitHub Desktop.
Monitor users without a crontab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cat <<EOF > /usr/local/etc/icinga-crontabs.sh | |
#!/usr/bin/env bash | |
function cleanup-dir() { | |
rm -Rf /icinga/crontabs | |
mkdir -p /icinga/crontabs | |
chmod -R 444 /icinga/ | |
chmod 555 /icinga /icinga/crontabs | |
} | |
function list-users() { | |
cut -d: -f1 /etc/passwd | |
} | |
function find-missing-crontabs() { | |
local username | |
for username in \$(list-users); do | |
if [ ! -f "/var/spool/cron/\${username}" ]; then | |
echo 'the user '\${username}' does NOT has crontab entries' > /icinga/crontabs/\${username} | |
fi | |
done | |
} | |
cleanup-dir | |
find-missing-crontabs | |
EOF | |
chmod +x /usr/local/etc/icinga-crontabs.sh | |
crontab -l > ~/current-root-crontab | |
echo '*/5 * * * * /usr/local/etc/icinga-crontabs.sh 2>&1 > /dev/null' >> ~/current-root-crontab | |
cat ~/current-root-crontab | crontab - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run as root once to install it in the crontab of the root user. a file in /usr/local/etc/icinga-crontabs.sh will be created.