Lead Image © stillfx, 123RF.com

Lead Image © stillfx, 123RF.com

Cron alternatives fcron and hcron

Task Schedulers

Article from ADMIN 54/2019
By
The fcron and hcron scheduler alternatives to cron are suitable for computers that do not run around the clock, and each come with specific benefits.

Most computers don't run nonstop, not least with a view to saving electricity. However, you might still want to run some tasks automatically when you are not sitting in front of your computer: In the long run, launching a backup program manually all the time can be annoying. The classic cron scheduler lets you handle these tasks automatically, but if your PC is not running at the specified time, automatic execution is simply skipped.

Therefore, it makes more sense to assign regular tasks to a scheduler that performs routine tasks as soon as the computer is switched back on. I tested the fcron [1] and hcron [2] schedulers on Fedora 29 with the Backup Manager [3] program as the test application.

Installation

You can pick up RPM and DEB packages for hcron on the project website and easily install these on your system with the package manager after downloading.

Fcron can only be installed manually (Listing 1) and requires the GCC compiler and Sendmail. The FcronQ [4] graphical front end uses the Qt GUI framework. Therefore, you have to set up the Qt library for Python 3, as well as Python 3 (Listing 2, first line). For FcronQ, you only need to download, unpack, and install the source files (Listing 2, following lines).

Listing 1

Installing fcron

# dnf install gcc sendmail
[...]
$ wget http://fcron.free.fr/archives/fcron-3.2.1.src.tar.gz
$ tar xvf fcron-3.2.1.src.tar.gz
$ cd fcron-3.2.1
$ ./configure
$ gmake
[...]
# gmake install

Listing 2

Installing FcronQ

# dnf install python3 python3-PyQt5 python3-PyQt4
[...]
$ wget https://downloads.sourceforge.net/project/fcronq/FcronQ/0.5.0/FcronQ-0.5.0.tar.bz2
$ tar xvf FcronQ-0.5.0.tar.bz2
$ cd FcronQ/Build/
$ make all
$ make install-user
[... set up for root ...]
# make install

Once you have set up one of the two schedulers, you should become root, enable the service, and launch the program in the background:

# systemctl enable fcron
# systemctl start fcron

In the case of hcron, just change the service name in the above commands from fcron to hcron.

fcron

In the /etc/fcron.conf configuration file, you can set the fcron file paths and the paths to some programs. If you want to edit the tasks in the future with your favorite editor, also adjust the editor variable. You can also specify who can and cannot use fcron with /etc/fcron.allow and /etc/fcron.deny. By default, all users have access.

At the command line, the

fcrontab -e

command creates a task. Fcron then opens a file in the configured editor in which you can edit, comment out, create, or delete tasks. The structure of tasks is

<options> <frequency> <command>

Table 1 summarizes important fcrontab file options and how to use them. If an option is preceded by an exclamation mark (!) on a command line, it applies to all subsequent lines or until the next !reset. A leading %, @, or &, on the other hand, indicates that it only takes effect within the line.

Table 1

fcrontab Options

Option Example Function
bootrun(<bool>) bootrun(true) Runs a job after starting fcron or booting the system.
jitter(<seconds>) jitter(10) Delay job by up to 255 seconds if multiple jobs start at the same time.
mail(<bool>) mail(true) Inform users about the job result by email.
mailfrom(<email address>) mailfrom(root) Adds an address or username plus the domain to the From field.
mailto(<email address>) mailto(root) Adds an address or username plus the domain to the To field.
nice(<value>) nice(5) Job priority; varies from -20 (highest) to 19 (lowest).
nolog(<bool>) nolog(true) Write error messages only to the log.
noticenotrun(<bool>) noticenotrun(true) Notifies the user by email if a job has not been processed.
random(<bool>) random(true) Like jitter, but with a random number.
reset reset Reset option settings.
runas(<user>) runas(root) Process job with the rights of the specified user.
runatreboot(<Bool>) runatreboot Start job immediately after system boot.
runonce(<bool>) runonce(true) Do not reschedule the job once it has been executed.
stdout(<bool>) stdout(true) Output to the console if fcron is running in the foreground.
timezone(<timezone>) timezone(Europe/Berlin) Job specifications are valid for the specified time zone.

You define how often a command is processed by specifying a time in <Minute> <Hour> <Day> <Month> <Weekday> notation. The supported value ranges can be found in Table 2; the asterisk is used as a wildcard. To enter a command, simply type what you would normally type at the command line. Listing 3 shows some examples.

Table 2

Time Under fcron

Field Value
Minute  -59
Hour  -23
Day 1-31
Month 1-12
Weekday  -7, where   = 7 = Sunday

Listing 3

fcron Examples

## Execute the echo command at 10:05am on Sundays and on the 31st.
5 10 31 * 7 echo '''
## Run mycommand every day at 5:05, 5:35, 6:05, 6:35, 7:05, and 7:35.
& 05,35 5-7 * * * mycommand -u me -o file
## Pick up email daily at 20, 21, 22 and 24 minutes past the hour.
20-24~23 * * * * getmail
## Pick up email every 30 minutes.
@ 30 getmails -all
## Run the Save command with low priority at 3:45 daily except Sundays
## and inform user 'jim' about it. Process job after startup
## if the PC was not running at the scheduled time.
&nice(10),mailto(jim),bootrun 45 03 * * *~0 "save --our work"

After saving the fcrontab file, you can use the command

fcrontab -l

to look up the tasks created by the current user.

FcronQ

Instead of using the command line, you can also configure fcron in the FcronQ graphical front end (Figure 1), which you call as FcronQ.pyw. To avoid an error message on launch, add your account with administrative rights to the fcron group:

# usermod -a -G fcron <user>
Figure 1: In principle, FcronQ is more like a text editor, because the parameters do not have any special input masks.

At bottom left in the GUI, you can see whether the fcron daemon is currently running. Next to that, select the user for whom you want to create new tasks. After a right-click on the input area, create a new task by selecting Append . In the Status column at the top, activate or deactivate individual tasks by checking or unchecking the boxes. You can also add a comment to the task.

You can double-click to add an option in the Variables or Options column. The Frequency column contains the time variables, and the Command column shows the command to be processed. To test a command, right-click the respective task and select Run . If everything works, save the task from the menubar with Action | Save .

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
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=