3

I am just starting to learn cron jobs. Basically I am going to use webmin to manage my cron jobs, I am also reading some basic information about cron jobs.

So far I've learned that /etc/crontab stores the cronjobs and /var/spool/cron/crontabs has cron jobs for different users, and that when I do crontab -e I can see and edit the cron jobs for current user.

Root is the only user in my Ubuntu 14.04, and there are only several lines in the crontab files I found in above locations. However, in webmin, this is what I see

enter image description here

It is a lot more than what I see in those files. So my question is: where do all these cronjobs I see in webmin come from?

  • 1
    Cron doesn't just store jobs in /var/spool/cron/crontabs, take a look in /etc/cron*/* – steve May 2 '16 at 18:33
3

There are several places where cron-jobs are stored.

The main place, is /etc/crontab (and on some systems, this is the only one). This file is edited only by root, and often allows to specify which user the job should run as.

On some systems, there is also a directory - /etc/cron.d - which complement /etc/crontab. The files here contains line(s) like what is used for /etc/crontab (often with user to run as specified), and is basically added to /etc/crontab. It makes it easy for packages to add an entry to the main crontab-file.

Then there are the per-user crontabs - including for root, normal users, and some system-users (often added by packages) - which can be found under /var/spool/cron/crontab in user-specific files... this is what you edit with crontab -e. On some systems, some or all users may be blocked, by using /etc/cron.allow or /etc/cron.deny.

You can disable entries in various crontab-files by commenting them out with a #.

Finally we have directories called /etc/cron.hourly, cron.daily, cron.weekly and cron.monthly. These contains shell-scripts - not crontab-entries like /etc/cron.d. However, the cron-daemon will look at these directories, and run these scripts at appropriate times. You can find entries for "run.daily", "run.weekly" and similar - usually in /etc/crontab - which is what actually parse and runs these scripts. To disable scripts in these directories, removing the execute-permission should do the trick.

One other problem with these - and with cron in general - is if the computer is turned off, during the periods when some cron-entries should be run. If that is the case, these jobs may (almost) never be run at all. Some cron-daemons have mechanism to fix this, or an additional crond-like program is used (eg. anacron) - but in general, a computer running cron, should be on all the time.

In addition, the at-and batch-mechanism is run as cron-jobs on some systems, rather than by a dedicated daemon of it's own.

+++

Most of the strange entries you've seen, are shell-scripts added by packages into the /etc/cron.{hourly|daily|weekly|monthly}-directories. These may do things like flushing buffers, compressing logs, add updates, or do general clean-up. As mentioned, these are not really crontab-entries but shell-scripts... it's just that cron will check these directories, and run their contents from time to time.

Obviously webmin checks all cron-related directories, and lists all entries.

Unless the entry/script - in /etc/crontab, /etc/cron.d, /etc/cron.timespecific or /var/spool/cron/crontab/user - is for some service you know you and your system is absolutely not using (eg. uucp or news, on a computer not using uucp or running a news-server); it's probably best to leave these as they are. Most of these cron-jobs will be run at "off-hours" (like in the middle of the night) anyway, and shouldn't be very noticeable. After all, "If it isn't broken, don't fix it".

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.