]> granicus.if.org Git - fcron/blob - doc/en/faq.sgml
648da161b4d6aa23098ab0668d9bb458a2fdadcd
[fcron] / doc / en / faq.sgml
1 <!-- 
2 Fcron documentation
3 Copyright 2000-2012 Thibault Godouet <fcron@free.fr>
4 Permission is granted to copy, distribute and/or modify this
5 document under the terms of the GNU Free Documentation License,
6 Version 1.1 or any later version published by the Free Software
7 Foundation.
8 A copy of the license is included in gfdl.sgml.
9 -->
10
11
12 <sect1 id="faq">
13     <title>Frequently Asked Questions</title>
14     <para>This FAQ intends to complement the man pages by following a more
15 practical approach.</para>
16     <para>If you think a QA should be added, please mail me it!</para>
17     <qandaset>
18         <qandaentry>
19             <question>
20                 <para>How does fcron handle system clock adjustments?</para>
21             </question>
22             <answer>
23                 <para>
24        First, you must understand that fcron determines, for each job, its next
25 time and date of execution. It then determines which of those jobs would be the
26 next to run and then, sleeps until that job should be run. In other words, fcron
27 doesn't wake up like Vixie cron each minute to check all job in case one should
28 be run ... and it avoids some problems associated with clock adjusts.</para>
29                 <para>
30        This means that if the new time value is set into the past, fcron won't
31 run a particular job again. For instance, suppose the real time and system clock
32 are 3:00, so the next job cannot be scheduled to run before 3:00, as it would
33 have already been run and re-scheduled.</para>
34                 <para>
35        First, suppose you set your system clock into the past, say to 2:00,
36 Presuming that the last run was shortly before 3:00. then fcron will sleep until
37 the next job should be executed. The execution time for a job is determined by
38 identifying the last time that the job ran and computing the next scheduled
39 time. This means that the next scheduled time must be on or after 3:01.
40 Therefore, in this example, fcron will not run a job for at least one
41 hour.</para>
42                 <para>
43        Next, if you set the system time into the future, say to 4:00, fcron will
44 run every job scheduled between the old and the new time value once, regardless
45 of how many times it would have been scheduled. When fcron wakes up to run a job
46 after the time value has changed, it runs all the jobs which should have run
47 during the interval because they are scheduled to run in a past time.</para>
48                 <para>
49        As special case is when "@xxx" style scheduling rules are involved, you
50 must consider the "adjustment-interval". The "adjustment-interval" is the time
51 difference between the original system time and the new system time. The concerned
52 jobs will run at "adjust-interval" too
53 early or too late depending of the nature of the adjust.</para>
54                 <para>
55        To conclude, fcron behaves quite well for small clock adjusts. Each job
56 which should have run does so once, but not exactly at the correct time as if
57 the job were scheduled within the adjustment interval. But, if you have to make
58 a big change in the time and date, you should probably reset all the scheduled
59 "nextexe" by running "fcrontab -z" on all the fcrontabs.</para>
60             </answer>
61         </qandaentry>
62          <qandaentry>
63             <question>
64                <para>How does fcron handle daylight saving time changes?</para>
65             </question>
66             <answer>
67                <para>There are two types of daylight saving time change: 
68 the remove-one-hour change (for instance, "at 3:00, it will be 2:00"), 
69 and the add-one-hour one (for instance, "at 2:00, it will be 3:00").
70 In both cases, fcron will run the job only once (more precisely, it won't
71 run the job twice as many as it should have).</para>
72                <para>In the first case, the official time changes as follow
73 (in order of real chronological time): [x, 2:00] -> i1: [2:00, 3:00]
74  -> i2: [2:00, 3:00] -> [3:00, y]. i1 and i2 are the names of the two
75 intervals [2:00, 3:00]. For this kind of DST change, a job which should
76 run between 2:00 and 3:00 will run either in i1 or in i2, but not both.
77 Consequently, a job scheduled to run every day at 2:30 (for instance)
78 will be run only once. There is no way for a user to know if the job will
79 be run in i1 or i2.</para>
80                <para>In the second case, there is a gap in time:
81 the official time changes as follow (in order of real chronological time):
82 [x, 2:00] -> [3:00, y]. A job scheduled between 2:00 and 3:00 will get
83 run once, and only once, even if it should have been run several times.
84 For instance, a job which should have run every 10 minutes will run only
85 once, not 6 times, between 1:59 and 3:01. A job scheduled to run at
86 2:xx will run at 3:xx. For instance, if a job is scheduled to run
87 every day at 2:30, it will run at 3:30 the day of this kind of DST change.
88 </para>
89             </answer>
90          </qandaentry>
91          <qandaentry>
92             <question>
93                <para>What about fcron and software suspend 
94                   (aka. suspend to RAM, to disk)?</para>
95             </question>
96             <answer>
97                <para>We suppose here that you are using swsusp and the hibernate
98                   script to do a "suspend to disk", but it should be similar
99                   with other methods.</para>
100                <para>When you switch on your computer after a suspend to disk,
101                   the system time will be incorrect, and will then be corrected
102                   by the hibernate script. Before it is corrected, fcron may
103                   compute the time and date of the next execution of a job:
104                   the computation would then be incorrect (please see the entry
105                   about system clock adjustment in the present FAQ).</para>
106                <para>So you should have the hibernate script stop fcron before
107                   the suspend, and then restart it when the system is switched on,
108                   ie. put a line like "RestartServices fcron" in your hibernate.conf
109                   file. That way, the system time will always be correct when
110                   fcron runs (assuming that fcron is started after the system time
111                   is corrected).</para>
112             </answer>
113          </qandaentry>
114         <qandaentry>
115             <question>
116                 <para>How can I prevent fcrontab from considering the first
117 "word" of my command line as a user name i.e. "runas(word)"?</para>
118             </question>
119             <answer>
120                 <para>
121       Suppose you have an user called "echo" (weird idea ... :)) ). If you use
122 the line '* * * * * echo "Hello!"' in root's fcrontab, "echo" will be
123 interpreted as "runas(echo)".</para>
124                 <para>To avoid that, put your command in quotes:
125 <programlisting>* * * * * 'echo "Hello!"'</programlisting> will work as
126 expected as quotes are allowed for the shell command but not for the user
127 name.</para>
128             </answer>
129         </qandaentry>
130
131         <qandaentry>
132             <question>
133                 <para>
134        I have a job which usually terminates with a non-zero status. When it
135 does, I receive a email with the exit status even if the command had no output.
136 How can I avoid the email?</para>
137             </question>
138             <answer>
139                 <para>
140       You could disable email entirely by setting the "mail" option to "no". But,
141 if you still want to receive the standard output as email, you can add an command
142 which always evaluates to 0, like "/bin/true", after your primary command. This
143 will not affect your job nor create additional output. For example:</para>
144                 <programlisting>
145 * * * * * /a/non/zero/status/job ; /bin/true</programlisting>
146             </answer>
147         </qandaentry>
148
149         <qandaentry>
150             <question>
151                 <para>What does "loadavg" mean anyway?</para>
152             </question>
153             <answer>
154                 <para>
155       The "/proc/loadavg" file provides loadavg values. These values are (in
156 order): the system load averages for the past 1, 5, and 15 minutes; a count of
157 the (active tasks/active processes); the pid of last process run;
158                 </para>
159                 <para>
160       The active task count includes those processes marked as running or
161 uninterruptable. A load average is an estimate of the average number of
162 processes running within a specified period. The load averages are computed from
163 active task count. They are updated each time active task counts are taken.
164                 </para>
165                 <para>
166 <!-- It sure would be nice for some MathML here. --> 
167 The load average formula is: <programlisting>
168 loadavg(d,n) = active_task_cnt - (active_task_cnt - old_loadavg)*(1/exp(d/n)
169 </programlisting>
170 where: d is the time interval between active task count readings, typically every
171 5 seconds; n is the time over which the readings are averaged.
172                 </para>
173             </answer>
174         </qandaentry>
175
176         <qandaentry>
177             <question>
178                 <para>How can I use fcrontab in scripts?</para>
179             </question>
180             <answer>
181                 <para>
182       You can use pipes with "<command>fcrontab -l</command>" (list the
183 fcrontab) and "<command>fcrontab -</command>" (read the new fcrontab from
184 input). For example: </para>
185                 <screen> <command>echo -e "`fcrontab -l | grep -v exim`\n0 * * * *      /usr/sbin/exim -q" | fcrontab -</command></screen>
186                 <para>
187                   can be used to add a line. Another way to do it would be to:
188 list the fcrontab settings into a temporary file ("<command>fcrontab -l >
189 tmpfile</command>"); modify the temporary file ("<command>echo $LINE >>
190 tmpfile</command>"); replace the original fcrontab by the temporary; and
191 finally, remove the temporary file ("<command>fcrontab tmpfile ; rm -f
192 tmpfile</command>").
193                 </para>
194             </answer>
195         </qandaentry>
196
197         <qandaentry>
198             <question>
199                 <para>Can I use fcron from time to time, for instance in a
200 script?</para>
201             </question>
202             <answer>
203                 <para>Let's suppose you use fcron in your ppp-up script. Fcron
204 can permit you to run some jobs at connection startup, but not at each
205 connection, like it would be if the job was run directly by the ppp-up script:
206 for instance, only once every week.</para>
207                 <para><example>
208                         <title>Using fcron in a script: running a job once
209 every day, week, etc, at dialup connection</title>
210                         <para>You can use a script like:</para>
211                         <programlisting>
212 # A ppp-up script ... 
213 # run the jobs pending, then returns: 
214 fcron -f -y -o
215 </programlisting>
216                         <para>in conjunction with a fcrontab file like:</para>
217                         <programlisting>
218 # a fcrontab file ... 
219 %random(no),weekly,stdout * * /a/command/to/download/latest/mozilla/release 
220 %monthly,stdout * * * /update/junkbuster/config/files
221 </programlisting>
222                     </example></para>
223                 <para>You can also use fcron to run some jobs until the end of
224 the connection. For instance, you can make fetchmail retrieve emails more often
225 during connection: we suppose that it is configured to retrieve mails every
226 hour, which launches a dialup connection if necessary, and we want it to check
227 for mails every 5 minutes while connected.</para>
228                 <para><example>
229                         <title>Using fcron in a script: running a job until the
230 end of the connection</title>
231                         <para>ppp-up script:</para>
232                         <programlisting>
233 # A ppp-up script ... 
234 # run fcron at the beginning of the connection: 
235 fcron -b
236 </programlisting>
237                         <para>ppp-down script:</para>
238                         <programlisting>
239 # A ppp-down script ... 
240 # stop fcron at the end of the connection: 
241 # -- Warning: killall may have unwanted effect on non linux systems -- 
242 killall -TERM fcron
243 </programlisting>
244                         <para>the fcrontab:</para>
245                         <programlisting>
246 # a fcrontab file ... 
247 @volatile,first(0) 5 fetchmail
248 </programlisting>
249                     </example></para>
250
251                 <para>If you run fcron in several scripts, or if you run fcron
252 as a daemon and want also to run fcron in scripts, then you should use fcron,
253 fcrontab and fcrondyn's <option>--configfile</option>.</para>
254                 <para>For more details, see fcron's command line arguments
255 &argonce;, <option>--nosyslog</option>,
256 &argfirstsleep; and <option>--configfile</option> in <link
257 linkend="fcron.8">&fcron;(8)</link>, and fcrontab's options &optvolatile;,
258 &optstdout;, &optfirst; in <link
259 linkend="fcrontab.5">&fcrontab;(5)</link></para>
260             </answer>
261         </qandaentry>
262         
263         <qandaentry>
264             <question>
265                 <para>Can I run fcron without root's privileges?</para>
266             </question>
267             <answer>
268                 <para>Yes, you can. To do that, see the
269 following instructions, but please note that fcrondyn currently does *not* work
270 without root privileges.</para>
271                 <orderedlist>
272                     <listitem>
273                         <para>First, create a directory where you'll install fcron,
274  and some subdirectories:</para>
275                         <screen><prompt>bash$
276 </prompt> <command>mkdir /home/thib/fcron</command>
277 <prompt>bash$</prompt> <command>cd /home/thib/fcron</command>
278 <prompt>bash$</prompt> <command>mkdir doc man spool</command></screen>
279                     </listitem>
280                     <listitem>
281                         <para>Then, run configure with option 
282 <option>--with-run-non-privileged</option>, set all user names and groups to yours,
283 and set appropriately the paths:</para>
284                         <para><warning>
285                             <para>This option allows a non privileged user to run
286         fcron. When used, fcron does not change its rights before running a job
287         (i.e., if joe runs fcron, every job will run as joe).  It means that
288         <emphasis>YOU SHOULD NOT RUN FCRON AS A PRIVILEGED USER WHEN COMPILED
289         WITH THIS OPTION</emphasis> or you'll have a serious security
290         hole.</para> </warning></para>
291                         <screen><prompt>bash$
292 </prompt> <command>./configure --with-run-non-privileged --with-rootname=thib
293 --with-rootgroup=thib --with-username=thib --with-groupname=thib
294 --with-etcdir=/home/thib/fcron --with-piddir=/home/thib/fcron
295 --with-fifodir=/home/thib/fcron --with-spooldir=/home/thib/fcron/spool
296 --with-docdir=/home/thib/fcron/doc --prefix=/home/thib/fcron</command></screen>
297                     </listitem>
298                 </orderedlist>
299                 <para>The rest of the installation is described in the
300 <link linkend="install">install file</link>.</para>
301             </answer>
302         </qandaentry>
303
304          <qandaentry>
305             <question>
306                <para>Has fcron some incompatibilities with Vixie cron?</para>
307             </question>
308             <answer>
309                <para>As far as I know, fcron supports Vixie cron's crontab syntax
310                   fully. You should be able to use a crontab
311                   with fcron with no modification (if not please
312                   contact me at &email;).</para>
313                <para>The main problem is about the management of the system (f)crontab.
314                   Vixie cron monitors the changes on /etc/crontab every minute,
315                   and automatically takes into account the changes if any.
316                   As for now, fcron does not do that by itself.
317                   Fcron does not support the
318                   /etc/cron.d/ directory either, as it is just an extension to the /etc/crontab
319                   file.
320                   However /etc/cron.{daily,weekly,monthly} directories will work
321                   in fcron just fine: they are supported through the run-parts program, just as Vixie cron).</para>
322                <para>So if you want to replace Vixie cron by fcron transparently,
323                   all you have to do is create a /usr/bin/crontab link to
324                   /usr/bin/fcrontab, and reinstall the system (f)crontab
325                   with 'fcrontab /etc/crontab' every time you modify it
326                   (if you needed some more work than that, please let me know!).</para>
327                <para>You can also use the script script/check_system_crontabs
328                   to monitor for system (f)crontab changes, i.e. changes to /etc/(f)crontab
329                   and /etc/cron.d/. When it detects a change, it will generate
330                   a new system fcrontab, and install it automatically.
331                   Should you choose to use that script, please take
332                   a look at the beginning of the script: you will find insctructions
333                   on how to use it -- and a few warnings you should pay attention to.
334                   With this script, the fcron's behavior should be very similar
335                   to Vixie cron regarding /etc/crontab and /etc/cron.d/.
336                </para>
337             </answer>
338          </qandaentry>
339          <qandaentry>
340             <question>
341                <para>How can I emulate an anacron entry?</para>
342             </question>
343             <answer>
344                <para>As anacron, fcron does not assume that the system runs permanently.
345                   Thus, fcron features similar functionalities to anacron, but it
346                   has different means to achieve it, in other words other ways to define
347                   when a job should run. Fcron is in general much more flexible
348                   than anacron.
349                   The best thing to do is to have look at
350                   <link linkend="fcrontab.5">&fcrontab;(5),</link> and choose the
351                   type of line which is the most appropriate for your needs (this is
352                   likely to be a @-line or a %-line).</para>
353                <para>On a Debian/Ubuntu, the default /etc/anacrontab looks like:<para>
354 <programlisting>1       5       cron.daily       nice run-parts --report /etc/cron.daily
355 7       10      cron.weekly      nice run-parts --report /etc/cron.weekly
356 @monthly        15      cron.monthly nice run-parts --report /etc/cron.monthly
357 </programlisting>
358                <para>A close fcron equivalent would be (see &optserial;):<para>
359 <programlisting># Run once a day/week/month, and ensure only one of those tasks is run at a time:
360 !reset
361 !serial,nice(10)
362 %daily * * run-parts --report /etc/cron.daily
363 %weekly * * run-parts --report /etc/cron.weekly
364 %monthly * * * run-parts --report /etc/cron.monthly</programlisting>
365                <para>Or you could go for something a bit more specific (see &optlavg;, &optnoticenotrun;):<para>
366 <programlisting># Only run the tasks out of office-hours when the system load is low
367 # and send an email to the user if fcron couldn't run the job:
368 !reset
369 !serial,lavg(0.5,1,1.5),noticenotrun,nice(10),mailto(admin@yourdomain.com)
370 %daily * 0-9,18-23 run-parts --report /etc/cron.daily
371 %weekly * 0-9,18-23 run-parts --report /etc/cron.weekly
372 %monthly * 0-9,18-23 * run-parts --report /etc/cron.monthly</programlisting>
373                <para>Also, if you do want to emulate an anacron entry of the form:</para>
374                <programlisting>0 delay job-identity /your/command</programlisting>
375                <para>then you can use something as:</para>
376                <programlisting>@runonce delay /your/command</programlisting>
377             </answer>
378          </qandaentry>
379          <qandaentry>
380             <question>
381                <para>How can I emulate a Vixie cron @reboot entry?</para>
382             </question>
383             <answer>
384                <para>No need to emulate any more, as
385                 <link linkend="fcrontab.5.shortcuts">Vixie cron shortcuts</link>,
386                  including @reboot, are now supported by fcron!</para>
387             </answer>
388          </qandaentry>
389     </qandaset>
390 </sect1>
391
392 <!-- Keep this comment at the end of the file
393 Local variables:
394 mode: sgml
395 sgml-parent-document:("fcron-doc.sgml" "book" "chapter" "sect1" "")
396 End:
397 -->