UC-7400-LX Plus User’s Manual
Managing Embedded Linux
3-11
Cron—Daemon for Executing Scheduled Commands
Cron is a scheduling service in Linux. Cron wakes up every minute, and checks the configuration
file named crontab to see if any scheduled command should be run in the current minute.
Crontab is located in the
/etc/cron.d
directory. Modify the file
/etc/cron.d/crontab
to set up your
scheduled applications. Crontab has the following format:
mm h dom
mon dow
user
command
min hour
date
month
week
user
command
0-59
0-23 1-31 1-12 0-6
(0
is
Sunday)
The following example demonstrates how to use Cron.
How to use cron to update the system time and RTC time every day at 8:00.
STEP1: Write a shell script named fixtime.sh and save it to /home/.
#!/bin/sh
ntpdate time.nist.gov
hwclock –-systohc
exit 0
STEP2: Change the mode of fixtime.sh
#chmod 755 fixtime.sh
STEP3: Modify the file /etc/cron.d/crontab to run fixtime.sh at 8:00 every day.
Add the following line to the end of crontab:
* 8 * * * root/home/fixtime.sh
STEP4: Enable the cron daemon manually.
#/etc/init.d/cron start
STEP5: Enable cron when the system boots up.
Add the following line to the file /etc/init.d/rc.local
#/etc/init.d/cron start
By default, cron service is disabled on boot. To enable cron service, please refer to the section
“Enabling and Disabling Daemons” in this chapter.