Difference between revisions of "Cron entry"

From SME Server
Jump to navigationJump to search
Line 15: Line 15:
 
Custom templates survive updates and are included in a regular backup.
 
Custom templates survive updates and are included in a regular backup.
  
Make directory for custom template
+
Check for a custom template directory. If one doesn't exist, make the directory for custom template with the following command
  
 
  mkdir -p /etc/e-smith/templates-custom/etc/crontab
 
  mkdir -p /etc/e-smith/templates-custom/etc/crontab
Line 29: Line 29:
  
 
Syntax: (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) (user) (command)
 
Syntax: (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) (user) (command)
 +
        Minute  Hour  Day    Month of Year    Day of Week
  
 
Save and exit.
 
Save and exit.

Revision as of 22:22, 6 October 2015


PythonIcon.png Skill level: Medium
The instructions on this page require a basic knowledge of linux.


Description

How to automatically run a command periodically with Cron daemon.

Cron is a time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as connecting to the Internet and downloading email. From Wikipedia

Cron daemon is the Unix and GNU/Linux equivalent to Scheduled Tasks in Windows.

Custom template

This is the preferred method on SME Server, see documentation. Custom templates survive updates and are included in a regular backup.

Check for a custom template directory. If one doesn't exist, make the directory for custom template with the following command

mkdir -p /etc/e-smith/templates-custom/etc/crontab

Create and open a file with the text editor nano:

nano /etc/e-smith/templates-custom/etc/crontab/your_file_name

Add your cron entries, example for running a script daily at 16,00:

# Run custom script with cron
00 16 * * * root /root/cronjobs/external_ip.sh

Syntax: (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) (user) (command)

       Minute  Hour   Day    Month of Year     Day of Week

Save and exit.

Regenerate the template:

expand-template /etc/crontab

Verify your new entry in the regenerated crontab:

more /etc/crontab

Restart the cron daemon:

service crond restart

Cron directorys

This method is simple, but will not be included in a regular backup and might have problems with updates and upgrades.

There are four directorys in /etc/: cron.hourly, cron.daily, cron.weekly and cron.monthly.

Any executable script dropped in these will be executed automatically each period (indicated by the directory name).

Notes

Cron jobs are executed by the user admin (which is an alias for root).

Cron job results are usually sent by email to the administrator.

A script fired by a cron entry must be executable.

Contribs

Crontab Manager is a contribs which is able to do automatically what is needed above.

Links

Forum post 1 | Forum post 2

Developers Manual on Configuration file templates

Crontab Manager