32

On various systems that I administer, there are cron scripts that get run via the commonly-used /etc/cron.{hourly,daily,weekly} layout. What I want to know is whether there's any common 'disable this script' functionality.

Obviously, simply deleting something out of a given directory will disable it, but I'm looking for a more permanent solution. Deleting /etc/cron.daily/slocate will work to disable the nightly updatedb on my home machine (where I never use slocate), but next time I upgrade the slocate package, I'm pretty sure it'll reappear.

The two distributions I'm most interested in are Gentoo and OpenSUSE, but I'm hoping there's a widely-implemented mechanism. Both distros as I have them use vixie-cron (not sure it matters).

benizi
  • 472

8 Answers8

54

You should be able to chmod -x scriptname to disable a script but leave the file in place.

19

run-parts does not execute jobs which have a dot in their name, so

mv /etc/cron.d/job /etc/cron.d/job.disabled

will do the trick.

chrisv
  • 317
12

Usually cron.daily is invoked via /etc/crontab through a line like e.g.

run-parts --report /etc/cron.daily

man run-parts gives you the options.

run-parts --test /etc/cron.daily shows which jobs are executed without running them.

I prefer to make a subdir 'Disabled' and move my jobs there.

In any case if you update a package it is likely that the job gets into place again or that removed 'x' bits get restored

Simon East
  • 1,514
Peter
  • 121
  • 1
  • 2
1

You can remove slocate package if you never use it.

Maxfer
  • 191
1

If you use cfengine (https://cfengine.com/) you could do this with disable. You just write a promise file for a group of hosts and it will apply itself in the next cfagent run. Doing this with puppet or chef or whatever should also be quite simple.

Bass
  • 103
  • 4
natxo asenjo
  • 5,909
1

The /etc/cron.daily et. al. scripts are run by a script called run-parts. That script varies. For example the --test switch mentioned above isn't on the machine I'm using at this instant.

Run-parts is a bash script. It a generally useful tool for running all the scripts in the directory it's given as an argument. It usually found at /usr/bin/run-parts.

It has a tangle of logic for deciding what to run. That code holds the answer to your question, but it varies too. So you need to read the code to be safe.

In the version I'm looking at it has logic that, when working on directory <foo>, checks for <foo>/jobs.deny. If that exists it declines to run any script that is mentioned in that file on a line, alone. Assuming you have this functionality it's awesome because it will keep working when the package that installs is installed or upgraded.

Ben Hyde
  • 111
1

If dealing with RHEL and derivates (which provides the crontabs package), you can explicitly disable a job by putting its name into the jobs.deny file.

From crontabs / run-parts man page:

The execution of files can be allowed or denied by creating file jobs.allow or jobs.deny which worked similar as other allow/deny config files. The file must be created in the specified directory.

Example /etc/cron.daily/jobs.deny could contain for example 0logwatch which forbid execution of this script.

shodanshok
  • 52,255
-1

If you don't want the user-crontabs either, just disable crond in your service-list.

In Debian and versions based on Debian this is simply a matter of removing the symlink from the appropriate /etc/rcX.d (for runlevel X).

I don't know how you handle services in SUSE or Gentoo.

jishi
  • 928