Copyright © 2000-2004 Thibault Godouet | Fcron 2.9.4 (dev release) | Web page : http://fcron.free.fr |
Fcron documentation | ||
---|---|---|
Prev | Chapter 2. Using fcron ... | Next |
This FAQ intends to complement the man pages by following a more practical approach.
If you think a QA should be added, please mail me it !
First, you must understand that fcron determines, for each job, its next time and date of execution. It then determines which of those jobs would be the next to run and then, sleeps until that job should be run. In other words, fcron doesn't wake up like Vixie cron each minute to check all job in case one should be run ... and it avoids some problems associated with clock adjusts.
This means that if the new time value is set into the past, fcron won't run a particular job again. For instance, suppose the real time and system clock are 3:00, so the next job cannot be scheduled to run before 3:00, as it would have already been run and re-scheduled.
First, suppose you set your system clock into the past, say to 2:00, Presuming that the last run was shortly before 3:00. then fcron will sleep until the next job should be executed. The execution time for a job is determined by identifying the last time that the job ran and computing the next scheduled time. This means that the next scheduled time must be on or after 3:01. Therefore, in this example, fcron will not run a job for at least one hour.
Next, if you set the system time into the future, say to 4:00, fcron will run every job scheduled between the old and the new time value once, regardless of how many times it would have been scheduled. When fcron wakes up to run a job after the time value has changed, it runs all the jobs which should have run during the interval because they are scheduled to run in a past time.
As special case is when "@xxx" style scheduling rules are involved, you must consider the "adjustment-interval". The "adjustment-interval" is the time difference between the original system time and the new system time. If the ... run at "adjust-interval" too early or too late depending of the nature of the adjust.
To conclude, fcron behaves quite well for small clock adjusts. Each job which should have run does so once, but not exactly at the correct time as if the job were scheduled within the adjustment interval. But, if you have to make a big change in the time and date, you should probably reset all the scheduled "nextexe" by running "fcrontab -z" on all the fcrontabs.
Suppose you have an user called "echo" (weird idea ... :)) ). If you use the line '* * * * * echo "Hello !"' in root's fcrontab, "echo" will be interpreted as "runas(echo)".
To suppress that, put your command in quotes :
* * * * * 'echo "Hello !"' |
You could disable mail entirely by setting the "mail" option to "no". But, if you still want to receive the standard output as mail, you can add an command which always evaluates to 0, like "/bin/true", after your primary command. This will not affect your job nor create additional output. For example:
* * * * * /a/non/zero/status/job ; /bin/true |
The "/proc/loadavg" file provides loadavg values. These values are (in order): the system load averages for the past 1, 5, and 15 minutes; a count of the (active tasks/active processes); the pid of last process run;
The active task count includes those processes marked as running or uninterruptable. A load average is an estimate of the average number of processes running within a specified period. The load averages are computed from active task count. They are updated each time active task counts are taken.
The load average formula is:
loadavg(d,n) = active_task_cnt - (active_task_cnt - old_loadavg)*(1/exp(d/n) |
You can use pipes with "fcrontab -l" (list the fcrontab) and "fcrontab -" (read the new fcrontab from input). For example :
echo -e "`fcrontab -l | grep -v exim`\n0 * * * * /usr/sbin/exim -q" | fcrontab - |
can be used to add a line. Another way to do it would be to: list the fcrontab settings into a temporary file ("fcrontab -l > tmpfile"); modify the temporary file ("echo $LINE >> tmpfile"); replace the original fcrontab by the temporary; and finally, remove the temporary file ("fcrontab tmpfile ; rm -f tmpfile").
Let's suppose you use fcron in your ppp-up script. Fcron can permit you to run some jobs at connection startup, but not at each connection, like it would be if the job was run directly by the ppp-up script : for instance, only once every week.
Example 2-5. Using fcron in a script : running a job once every day, week, etc, at dialup connection
You can use a script like :
# A ppp-up script ... # run the jobs pending, then returns : fcron -f -y -o |
in conjunction with a fcrontab file like :
# a fcrontab file ... %random(no),weekly,stdout * * /a/command/to/download/latest/mozilla/release %monthly,stdout * * * /update/junkbuster/config/files |
You can also use fcron to run some jobs until the end of the connection. For instance, you can make fetchmail retrieve mails more often during connection : we suppose that it is configured to retrieve mails every hour, which launches a dialup connection if necessary, and we want it to check for mails every 5 minutes while connected.
Example 2-6. Using fcron in a script : running a job until the end of the connection
ppp-up script :
# A ppp-up script ... # run fcron at the beginning of the connection : fcron -b |
ppp-down script :
# A ppp-down script ... # stop fcron at the end of the connection : # -- Warning : killall may have unwanted effect on non linux systems -- killall -TERM fcron |
the fcrontab :
# a fcrontab file ... @volatile,first(0) 5 fetchmail |
If you run fcron in several scripts, or if you run fcron as a daemon and want also to run fcron in scripts, then you should use fcron, fcrontab and fcrondyn's --configfile.
For more details, see fcron's options --once, --nosyslog, --firstsleep and --configfile in fcron(8), and fcrontab's options volatile, stdout, first in fcrontab(5)
Yes, you can. To do that, see the following instructions, but please note that fcrondyn currently does *not* work without root privileges.
First, create a directory where you'll install fcron, and some subdirectories :
bash$ mkdir /home/thib/fcron bash$ cd /home/thib/fcron bash$ mkdir doc man spool |
Then, run configure with option --with-run-non-privileged, set all user names and groups to yours, and set appropriately the paths :
Warning |
This option allows a non privileged user to run fcron. When used, fcron does not change its rights before running a job (i.e., if joe runs fcron, every job will run as joe). It means that YOU SHOULD NOT RUN FCRON AS A PRIVILEGED USER WHEN COMPILED WITH THIS OPTION or you'll have a serious security hole. |
bash$ ./configure --with-run-non-privileged --with-rootname=thib --with-rootgroup=thib --with-username=thib --with-groupname=thib --with-etcdir=/home/thib/fcron --with-piddir=/home/thib/fcron --with-fifodir=/home/thib/fcron --with-spooldir=/home/thib/fcron/spool --with-docdir=/home/thib/fcron/doc --prefix=/home/thib/fcron |
The rest of the installation is described in the install file.