This is an old revision of the document!


Gentoo Linux

fcron refuses to stop with start-stop-daemon –pidfile ${FCRON_PIDFILE} if there are multiple PIDs. Change the line in /etc/init.d/fcron to this instead:

start-stop-daemon --stop -n fcron

bug 388371

fcron Samples

See man 5 fcrontab

# Get our mails every 30 minutes 
@ 30 getmails -all

# make some security tests every 48 hours of system up time, 
# force a mail to be sent to root even if there is no output 
@mailto(root),forcemail 2d /etc/security/msec/cron-sh/
       # use /bin/bash to run commands, ignoring what /etc/passwd says

       # mail output to thib, no matter whose fcrontab this is

       # define a variable which is equivalent to " Hello thib and paul! "
       # here the newline characters are escaped by a backslash (\)
       # and quotes are used to force to keep leading and trailing blanks
       TEXT= " Hello\
        thib and\
        paul! "

       # we want to use serial but not bootrun:

       # run after five minutes of execution the first time,
       # then run every hour
       @first(5) 1h   echo "Run every hour"

       # run every day
       @ 1d echo "fcron daily"

       # run once between in the morning and once in the afternoon
       #  if systems is running at any moment of these time intervals
       %hours * 8-12,14-18 * * * echo "Hey boss, I'm working today!"

       # run once a week during our lunch
       %weekly * 12-13 echo "I left my system on at least once \
        at lunch time this week."

       # run every Sunday and Saturday at 9:05
       5 9 * * sat,sun echo "Good morning Thibault!"

       # run every even days of march at 18:00, except on 16th
       0 18 2-30/2~16 Mar * echo "It's time to go back home!"

       # the line above is equivalent to
       & 0 18 2-30/2~16 Mar * echo "It's time to go back home!"

       # reset options to default and set runfreq for lines below

       # run once every 7 matches (thanks to the declaration above),
       # so if system is running every day at 10:00, this will be
       # run once a week
       & 0 10 * * * echo "if you got this message last time 7 days ago,\
        this computer has been running every day at 10:00 last week.\
        If you got the message 8 days ago, then the system has been down \
        one day at 10:00 since you got it, etc"

       # wait every hour for a 5 minutes load average under 0.9
       @lavg5(0.9) 1h echo "The system load average is low"

       # wait a maximum of 5 hours every day for a fall of the load average
       @lavgand,lavg(1,2.0,3.0),until(5h) 1d echo "Load average is going down"

       # wait for the best moment to run a heavy job
       @lavgor,lavg(0.8,1.2,1.5),nice(10) 1w echo "This is a heavy job"

       # run once every night between either 21:00 and 23:00 or
       #   between 3:00 and 6:00
       %nightly,lavg(1.5,2,2) * 21-23,3-6 echo "It's time to retrieve \
        the latest release of Mozilla!"

fcron vs. vixie-cron

fcron uses a dedicated user to run root commands (systab). vixie-cron uses root to run the commands as, and set it's own variables (see /etc/crontab) that override default environment variables (such as HOME). I like fcron better because it is more predictable and doesn't change things around. Debugging scripts that run as cron jobs is tricky, and the less surprises, the better.