Difference between revisions of "Cron"

From ZoneMinder Wiki
Jump to navigationJump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Here is an example crontab you might use with Zoneminder. These are put in /etc/crontab which is easier than managing individual user crontabs. Used in Devuan Jessie, ZM 1.30.
Here is an example crontab you might use with Zoneminder. These are put in /etc/crontab which is easier than managing individual user crontabs. Used in Devuan Jessie, ZM 1.30 - 1.34.


== Example Crontab ==
== Example Crontab ==
Line 31: Line 31:
* This example is intended for /etc/crontab. You do not specify user when you run a # crontab -e.
* This example is intended for /etc/crontab. You do not specify user when you run a # crontab -e.
* For full details on Run States see: http://zoneminder.readthedocs.io/en/stable/faq.html#how-can-i-get-zm-to-do-different-things-at-different-times-of-day-or-week
* For full details on Run States see: http://zoneminder.readthedocs.io/en/stable/faq.html#how-can-i-get-zm-to-do-different-things-at-different-times-of-day-or-week
* Cron is sh, not bash. This means certain functionality won't work. e.g. $RANDOM will not work in sh. This can be avoided by running scripts with the bash crunchbang from cron.
[[Category:Dummies_Guide]]

Latest revision as of 00:07, 18 November 2020

Here is an example crontab you might use with Zoneminder. These are put in /etc/crontab which is easier than managing individual user crontabs. Used in Devuan Jessie, ZM 1.30 - 1.34.

Example Crontab

#disable cron emails
MAILTO=""

#backup
00 5 * * 6 root mysqladmin -u zmuser --password=zmpass zm > /somewhere/zmdbbackup.sql

#reboot once a month
00 1 1 * * root /sbin/reboot

#monitor HDD health
00 1 * * 1 root /usr/sbin/smartctl -t short /dev/sda

30 1 * * 1 root /usr/sbin/smartctl -l selftest /dev/sda > /somewhere/HDD_HealthReport.txt

35 1 * * 1 root echo "hdd report" | mail  -A /somewhere/HDD_HealthReport.txt -s "HD SMART TEST FOR ZM SERVER" email@address.com

#set different runstate for weekends
00 1 * * 6  www-data  /usr/bin/zmpkg.pl Weekend
00 23 * * 7  www-data  /usr/bin/zmpkg.pl Weekday

Tips

  • The backup will give you a DB file but not save any of your images/videos. The DB can restore your configuration only. You might want to backup videos separately. Also note, There is a better backup script on the forums, which saves multiple copies of the database.
  • Email must be configured to use mail -s (see links in SMS_Notifications for a quick setup).
  • When changing run state via zmpkg.pl you must use www-data user. Combine this with the possible feature from SMS_Notifications.
  • This example is intended for /etc/crontab. You do not specify user when you run a # crontab -e.
  • For full details on Run States see: http://zoneminder.readthedocs.io/en/stable/faq.html#how-can-i-get-zm-to-do-different-things-at-different-times-of-day-or-week
  • Cron is sh, not bash. This means certain functionality won't work. e.g. $RANDOM will not work in sh. This can be avoided by running scripts with the bash crunchbang from cron.