How-to create cronjob inside the Checkmk site
LAST TESTED ON CHECKMK 2.3.0P1
List all the cronjobs enabled on your checkmk site:
With crontab -l executed as site user, you will get an overview of all the configured cronjobs inside the Checkmk site.
These are all the cronjobs available by default on a checkmk site:
OMD[checkmk]:~$ crontab -l # # Do not edit this file. It will be recreated each time OMD # is started or reloaded. # # execute 'omd reload crontab' # to rebuild this file out of /omd/sites/checkmk/etc/cron.d/* # # --ENVIRONMENT------------------------------------------------ SHELL=/bin/bash BASH_ENV=/omd/sites/checkmk/.profile OMD_ROOT=/omd/sites/checkmk OMD_SITE=checkmk PATH=/omd/sites/checkmk/local/bin:/omd/sites/checkmk/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin MAILTO="" # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_bulk_notify # Needed for bulk notifcations. # Only execute cmk --notify when the microcore is currently not enabled. * * * * * [ ! -e /omd/sites/checkmk/etc/check_mk/conf.d/microcore.mk -a -d /omd/sites/checkmk/var/check_mk/notify/bulk ] && cmk --notify send-bulks # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_cleanup_pdf_tmp_files # Once a day, at 00:15, search for PDF tmp files older than 1 day and delete them 15 0 * * * [ -d "$OMD_ROOT/tmp/check_mk/pdf" ] && find $OMD_ROOT/tmp/check_mk/pdf -maxdepth 1 -name tmp\* -mtime 1 -delete # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_cleanup_piggyback # Once a day, at 00:10, cleanup outdated piggyback files 10 0 * * * cmk --cleanup-piggyback # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_dns_cache # Once a day, at 00:05, update IP address cache of all Check_MK hosts 5 0 * * * cmk --update-dns-cache # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_inventory # Every 5 minutes autoinventory hosts marked by inventory check */5 * * * * cmk --inventorize-marked-hosts # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_license_email_notification # Run every day at 00:00 0 0 * * * /omd/sites/checkmk/bin/cmk-license-email-notification # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_multisite # Run Multisite regular jobs, e.g. scheduled reports * * * * * . $OMD_ROOT/etc/omd/site.conf ; curl http://localhost:$CONFIG_APACHE_TCP_PORT/checkmk/check_mk/run_cron.py >/dev/null 2>&1 # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/cmk_update_license_usage # Run every 30 minutes between 8am and 5pm # Note: in update_license_usage() the next (random) time point is set between 8am and 4pm */30 8-17 * * * /omd/sites/checkmk/bin/cmk-update-license-usage # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/diskspace # # Run every hour, 5 minutes after full hour # 5 * * * * diskspace >> $OMD_ROOT/var/log/diskspace.log 2>&1 # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/logrotate # # Daily Logrotate # 0 0 * * * $OMD_ROOT/bin/logrotate -s $OMD_ROOT/tmp/run/logrotate.state $OMD_ROOT/etc/logrotate.conf >/dev/null 2>&1 # ------------------------------------------------------------ # /omd/sites/checkmk/etc/cron.d/php-sessions # Once a day, at 00:10, search for PHP sessions that are older than 1 day and delete them 10 0 * * * find $OMD_ROOT/tmp/php/session -name sess_\* -mtime +1 -delete # ------------------------------------------------------------
Configure your new cronjob:
By default, all the cron jobs associated with the checkmk site are stored inside the ~/etc/cron.d .
To create a new cron job, you need to create a new file, as site user, inside the ~/etc/cron.d directory.
Example: ~/etc/cron.d/myjob:
# My cronjob */5 * * * * $OMD_ROOT/local/myjob --params >/dev/null 2>&1
Replace the $OMD_ROOT/local/myjob --params >/dev/null 2>&1 with the path of your script and the needed parameters.
To enable the newly created cronjob, you need to reload crontab, as site user:
OMD[checkmk]:~$ omd reload crontab Removing Crontab...OK Initializing Crontab...OK
Check if the new cronjob was enabled (troubleshooting):
To check if the newly created cronjob is enabled, do this:
OMD[checkmk]:~$ crontab -l | grep myjob #myjob */5 * * * * $OMD_ROOT/local/myjob --params >/dev/null 2>&1
If you need help configuring the execution time for your cronjob, you can use the Crontab.guru tool.
Related articles