Cron alternatives fcron and hcron

Task Schedulers

hcron

Hcron uses key-value pairs (Table 3) for configuration, so you don't need to know where to enter minutes, hours, days, and so on in the call syntax. As with fcron, you can use asterisks for arbitrary information. In hcron, the individual tasks are referred to as events and can be stored in separate files to keep things tidy.

Table 3

hcron Events

Key Function (Values)
Mandatory Data
host Hostname
command Command to be executed
notify_email Email address for notification
notify_message Notification text
when_month Execution: month (1-12)
when_day Execution: day of the month (1-31)
when_hour Execution: hour ( -23)
when_minute Execution: minute ( -59)
when_dow Execution: weekday ( -6,  =Sunday)
Optional Data
as_user User account for executing the command
failover_event Alternative event in case of failure
next_event Next event to execute after successfully starting an event
notify_subject Email notification subject
when_year Version: year (2000-2050)

The Scheduler configuration files can be found in the /etc/hcron/ folder. In the hcron.allow file, enter a username for anyone allowed to execute commands from an event file. You also need a directory for this user's events. It must be located in a subfolder that uses the fully qualified domain name (FQDN):

$ hcron-info --fqdn
[FQDN]

Next, create the corresponding events directory, and when you get there, use the hcron-event command to create an empty event file that already contains the most important keys:

$ mkdir -p ~/.hcron/<FQDN>/events
$ hcron-event ~/.hcron/<FQDN>/events/event-backup.txt
[... Fill event file ...]

In this example, the event file is named event-backup.txt.

To create an hcron event for Backup Manager that performs a daily backup run at 9:10pm, enter the keys and values shown in Listing 4 in the event-backup.txt file. After saving the file, hcron prompts you to restart the scheduler, which you can confirm by pressing Y . If you later edit an existing event file, you only need to restart the hcron scheduler with hcron-reload to notify hcron of the changes.

Listing 4

hcron Events

# event-backup.txt
as_user=<User>
host=<FQDN>
command=sudo backup-manager
notify_email=<User>@<FQDN>
notify_message=done
when_month=*
when_day=*
when_hour=21
when_minute=10
when_dow=*

Last but not least, use the calls

$ hcron-info allowed
yes
$ hcron-info es
accepted::/event-backup.txt

to check whether the current user is allowed to execute hcron events and, if so, where they reside.

Alternatives

The established vixie-cron scheduler and its fork cronie are used by default on several distributions. In contrast to fcron, neither cron nor vixie-cron resume operation if the computer was not running at the time of the scheduled event; however, another scheduler alternative named anacron does [5].

Cron also has graphical front ends, such as KCron [6], and you can even find websites where you can create a cronjob online [7]. The syntax of a standard job is the same for cron and fcron, so you can simply copy cronjobs to the corresponding fcrontab file, usually located in the /usr/var/spool/fcron/ directory. Additionally, the fcron syntax accommodates shortcuts from vixie-cron, so switching from vixie-cron to fcron is easy.

In addition to a comprehensive online tutorial [8] with several examples, fcron offers extended functions that are useful for load tests, among other things. A script can be executed several times a minute [9], which is only possible with the other tools by using the sleep command. Table 4 highlights further differences.

Table 4

Scheduler Differences

fcron cron/anacron
24/7 operation not required Interrupted operation requires anacron
Demon cron: demon; anacron: no demon
Tasks executable several times daily cron: several times daily; anacron: daily only
Extensive tutorial Several tutorials online
Manual installation Installation by package manager
Only one GUI available Multiple GUIs to choose from
Advanced syntax Fewer functions

Conclusions

Fcron, like cron, is fairly clumsy to use, whereas hcron is easier to manage because it uses key-value pairs in an event file. Moreover, hcron creates a template with all obligatory keys on request: You only have to enter the corresponding values. Additionally, hcron is easier to install and provides better logging. Ultimately, you have to decide for yourself which scheduler best suits you, according to your specific deployment requirements.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus