Score:3

Difference between anacron command options - n and -f

cw flag

I am currently using Ubuntu 20.04. My query is regarding the anacron command options -n and -f.

Does anacron -n command run all the jobs (daily, weekly and monthly) scheduled in anacron or it only runs the jobs scheduled to run today? I got the below output for this command sudo anacron -n -d:

Anacron 2.3 started on 2023-04-01
Normal exit (0 jobs run)

I got the below output for this command sudo anacron -f -d:

Anacron 2.3 started on 2023-04-01
Will run job `cron.daily' in 5 min.
Will run job `cron.weekly' in 10 min.
Will run job `cron.monthly' in 15 min.

Also when i combine both the -n and -f options, all the jobs started running without considering the delay.

Does anyone know how exactly both these options differ when using with anacron command?

Score:3
vn flag

In general, anacron works in such a way that it will only execute any job if it hasn't already been executed within its given "timespan" (hourly, daily, weekly and monthly).

So if you run anacron for the first time in a week, it will run the tasks scheduled for hourly, daily and weekly. If you run it just afterwards, no tasks will be run. If you run it after an hour, only jobs scheduled for hourly will be run etc.

To keep track of this, anacron saves a timestamp for each job run. And only if the scheduled "timespan" exceeds the timestamp the job is run again.

Now the -n and -f options are described in the anacron man page, and they do two distinctively different things.

  • The -f option forces all jobs to be (re)run, ignoring the timestamps. This means if you run anacron several times just after each other with the -f option, it will rerun all jobs - including those that are scheduled to only run daily, weekly and monthly.

  • The -n option tells anacron to run relevant jobs now, taking timestamps into account, but ignoring the delays set in /etc/anacrontab. The default delays (as evident from your output are):

    • cron.daily - 5 minutes
    • cron.weekly - 10 minutes
    • cron.monthly - 15 minutes

    In addition, the -n option also includes the -s option, so that the jobs are run in sequence (one after the other), as opposed to running the jobs for each "timespan" in parallel.

I think it's most clear to get an overview with a table:

Options Enforce timestamps Enforce delays Serial execution
none Yes Yes No
-s Yes Yes Yes
-n Yes No Yes
-f No Yes No
-fs No Yes Yes
-fn No No Yes
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.