0

I want my computer to shutdown at 1 a.m., but if I have already suspended it before that then the shutdown should not happen at all.

I have tried editing the crontab file, but when I resumed from suspension, anacron carried out the shutdown. Is there any way to stop anacron from doing this?

EDIT: I'm aware that I could disable anacron completely, but there are other cron jobs that requires anacron. Is there any workaround for this?

3

Don't schedule the shutdown with anacron. Schedule it as a cron job instead.

The purpose of anacron is to make sure that system maintenance tasks are run on a regular basis, even if the machine is powered off for periods at a time (in which case any jobs that should have been run during the downtime will run as soon as possible once the system is back on line and anacron is executed).

anacron is not the job scheduler you'd want to run a nightly shutdown job with, or anything else that is required to run at specific times.

Instead, add a cronjob for root:

0 1 * * * /sbin/poweroff

(or whatever other command you may use to power off your machine)

Also make sure that anacron is not used to run the job (check the anacrontab file).


There is absolutely no issues with running both cron and anacron jobs on the same machine. In fact, you should probably be running anacron from cron. Just make sure that jobs handled by cron are not also handled by anacron and vice versa.

In my own crontab for root, I have the following entries that executes anacron on reboots and at midnight:

@reboot /usr/local/sbin/anacron -ds
@daily  /usr/local/sbin/anacron -ds
  • Is there anyway to schedule a job as a cron job without triggering anacron? I know that I could just disable anacron altogether, but I have other cron jobs that need anacron. – PyGeek03 Oct 22 '17 at 3:52
  • @PyGeek03 Yes, just use crontab -e to edit your crontab and add the job there. And make sure that anacron is not running cron's jobs. – Kusalananda Oct 22 '17 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.