Skip to content

Instantly share code, notes, and snippets.

@mauricioprado00
Last active August 16, 2017 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioprado00/9c0b696a2cf0aa88b55c82be86af6ee7 to your computer and use it in GitHub Desktop.
Save mauricioprado00/9c0b696a2cf0aa88b55c82be86af6ee7 to your computer and use it in GitHub Desktop.
Monitor users without a crontab
#!/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 -
@mauricioprado00
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment