Cron is a time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.

learn more… | top users | synonyms (2)

51
votes
9answers
60k views

When does `cron.daily` run?

When do entries in cron.daily (and .weekly and .hourly) run, and is it configurable? I haven't found a definitive answer to this, and am hoping there is one. I'm running RHEL5 and CentOS 4, but for ...
38
votes
4answers
40k views

Running Cron every 2 hours

I have the cron job as shown below, and wanted it to run every 2 hours, but it keeps running every 2 minutes. Can someone tell me where I'm going wrong? * */2 * * * /path-to-script
35
votes
3answers
17k views

Why is my crontab not working, and how can I troubleshoot it?

This is a Canonical Question about using cron & crontab. The answer for 'Why is my crontab not working, and how can I troubleshoot it?' can be seen below. This addresses the cron system with ...
26
votes
4answers
40k views

What is the correct syntax to run cron every 4 hours?

I have the following syntax (which I think is correcT?) but it runs the command every minute! * */4 * * * /cmd.sh
25
votes
7answers
9k views

Prevent duplicate cron jobs running

I have scheduled a cron job to run every minute but sometimes the script takes more than a minute to finish and I don't want the jobs to start "stacking up" over each other. I guess this is a ...
24
votes
7answers
39k views

How to get e-mail from (failed) cron-jobs in Ubuntu?

I create cron-jobs in Ubuntu by placing the executable in one of /etc/cron.{daily,hourly,monthly,weekly}. There are lots of directories starting with cron: kent@rat:~$ ls -ld /etc/cron* drwxr-xr-x 2 ...
20
votes
3answers
6k views

What does * * * * * (five asterisks) in a cron file mean? [duplicate]

The first noncomment line in a legacy crontab file begins with five asterisks: * * * * * ([a_command]) >/dev/null 2>&1 The authors are gone, so I do not know their intent. What does ...
19
votes
6answers
7k views

Can I run a cron job more frequently than every minute?

Is it possible to run a cron job every 30 seconds without a sleep command?
19
votes
6answers
2k views

Outgrowing cron: what's the next scheduler?

We've been using cron for about as long as I can remember to handle all of our job scheduling needs. Everything from storage clones/snapshots to reports against databases to daily system reports to ...
18
votes
6answers
8k views

How to Modify a Cronjob Email Subject

I am running a half dozen different cron jobs from my hosting at Hostmonster.com. When a cronjob has been executed I receive an email with the output of the script. The email comes in the format of: ...
17
votes
5answers
8k views

job scheduling using crontab, what will happen when computer is shutdown during that time?

I schedules some tasks using crontab. But, I am wondering what will happen if my computer is shutdown during the time or it was turned off before the time when it was schedule to do something ? Does ...
16
votes
6answers
13k views

How to send the output from a cronjob to multiple e-mail addresses?

In the beginning of a crontab file you can use the MAILTO instruction to indicate you want the output to be sent as an e-mail to an e-mail address. I would like to send the output to multiple ...
16
votes
7answers
15k views

Can cron write job output to a log *by default* (instead of mail)?

We all know the right way to handle output from cron jobs is to redirect it to a file: 0 * * * * /bin/date >> /var/log/date.log 2>&1 However, sometimes admins are lazy, forgetful, or ...
15
votes
2answers
496 views

Is there a utility like cron, that schedules a job for later (but only once)?

I'm trying to design a program that sends a text when a certain (non-periodic) event occurs. Right now, I'd like a script that finds when this event occurs, and then schedules a (cron-like) job that ...
14
votes
7answers
12k views

How to change “From:” field for emails from Cron?

I use remote SMTP via nullmailer and it requires set From field to the specific name, but cron set it as root@my.sweet.server.com. How could I change it to something like me@ya.ru?
13
votes
2answers
534 views

How does cron handle remainders in “every so often” jobs

If I do this: */9 * * * * /path/to/wotnot At what times will the task run in two hours, starting at 09h00 Is it A: 09h00 09h09 09h18 09h27 09h36 09h45 09h54 10h03 10h12 10h21 10h30 10h39 10h48 ...
12
votes
6answers
520 views

How to keep cron from stampeding?

Say I have several cron scripts that need to run every 15 minutes. I could set them to run: */15 * * * * , but then they all run at the same time. It seems silly for the server to sit idle for ...
12
votes
2answers
2k views

What's wrong with my cronjob syntax, I'm trying to use a backtick (`)?

Here's what I'd like to automate: 00 08 * * * psql -Uuser database < query.sql | mail somone@null.com -s "query for `date +%Y-%m-%dZ%I:%M`" Here's the error message: /bin/sh: -c: line 0: ...
12
votes
11answers
11k views

Techniques to Monitor cron tasks?

Are there good techniques for monitoring cron tasks over a cluster? We're starting to use cron to launch tasks at daily intervals. A few ideas for checking out information: Add special application ...
12
votes
4answers
668 views

How to schedule server jobs more intelligently than with cron?

I run a job every minute to reindex my site's content. Today, the search engine died, and when I logged in there were hundreds of orphan processes that had been started by cron. Is there another ...
12
votes
3answers
5k views

Override MAILTO for a single crontab entry

We have a role account at work that has a pretty big crontab. Its MAILTO is pointed at a shared address, so that a number of us get notified if something fails. I'd like to add an entry to this ...
12
votes
4answers
9k views

How can I monitor what logrotate is doing?

How can I monitor what logrotate is doing in Ubuntu? Can the activity of logrotate be monitored?
12
votes
1answer
5k views

What is the correct way of getting crontab on CentOS 6?

I have a server running CentOS 6.2 minimal, but it doesn't appear to have crontab installed by default? crontab -e -bash: crontab: command not found In searching google, I found references to a ...
11
votes
5answers
10k views

How can I prevent cron from filling up my syslog?

I have a script which needs to be executed each minute. The problem is that cron is logging to /var/log/syslog each time it executes. I end up seeing something like this repeated over and over in ...
11
votes
7answers
23k views

Running a cron job manually and immediately

(I have already read How can I test a new cron script ?.) I have a specific problem (cron job doesn't appear to run, or run properly), but the issue is general: I'd like to debug scripts that are ...
11
votes
1answer
3k views

How does cron.d notify the system?

If I put a new script into /etc/cron.d/ how does the system know to insert it into the global crontab? Do I need to restart a process to pick it up? Does init run crontab every minute, and it'll ...
10
votes
4answers
535 views

Does 31 necessarily imply the end of the month in a cron job?

For cron job we know we can set time as below. # +------------ Minute (0 - 59) # | +---------- Hour (0 - 23) # | | +-------- Day of the Month (1 - 31) # | | | +------ Month (1 - 12) # | | | | +---- ...
10
votes
5answers
8k views

Using mysqldump in cron job without root password

If I login with the root password on my box I can simply type mysqldump --all-databases and I will get th expected "Dump". I setup a job in cron.daily to run and dump this to a backup drive. The ...
10
votes
3answers
6k views

Is there a way to validate /etc/crontab’s format?

I prefer to stick scheduled tasks in /etc/crontab so I can see at a glance what's scheduled to run, regardless of which user the task runs as. The only gotcha is that the format isn't validated on ...
9
votes
6answers
4k views

Robustly disabling specific cron.{hourly,daily,weekly} script

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 ...
9
votes
11answers
2k views

Is it safe to run apt-get update every night?

Is it safe to run apt-get update -y through cron on a production server?
9
votes
2answers
5k views

Better logging for cronjobs? Send cron output to syslog?

I am looking for a better way to log cronjobs. Most cronjobs tend to spam email or the console, get ignored, or create yet another logfile. In this case, I have a Nagios NSCA script which sends data ...
9
votes
5answers
8k views

Execute rsync command over ssh with an ssh agent via crontab

i have a cronjob: 0 9 * * * rsync -a mydir remote_machine: i installed this with 'crontab -e'. i have an ssh-agent running, and when i execute the rsync command itself it works w/o any user ...
9
votes
1answer
2k views

How do I make cron run every other Sunday on the OTHER Sunday?

I have a cron job that runs at 0 0 * * 0/2 -- i.e. every other Sunday. It just ran now, for instance. However, I want it to run on the other Sundays -- next Sunday, rather than this one. Another ...
8
votes
3answers
8k views

How can I test a new cron script?

I'm running on a couple of different Linux distros (Fedora 11, CentOS 5 and SuSE 10.2) and often run into a problem where a new script that I want to run as a cron job works fine when called direct ...
8
votes
4answers
677 views

Analyze and optimize crontabs [closed]

Is there a tool to graph, analyze and help optimize crontab execution? To clarify, I'm thinking of a tool which would generate a graph of when cron jobs are executed, and help the sysadmin reorganize ...
8
votes
3answers
7k views

What could cause “Permission denied” for command `crontab -e`?

Here's some output that I hope is helpful: nick@home-sv-1:~$ crontab -e /var/spool/cron/crontabs/nick: Permission denied nick@home-sv-1:~$ echo $EDITOR emacs nick@home-sv-1:~$ ls ...
7
votes
4answers
12k views

How to disable everything in crontab -l?

I just want to pause everything. Don't execute anything listed on crontab -l.
7
votes
3answers
3k views

Why is only one wget command working in my crontab?

I wish to fetch content from a PHP script on my server two times a day, altering a query variable lang to set what language we want, and save this content in two language specific files. This is my ...
7
votes
2answers
5k views

How do I edit the crontab of another user on my linux server?

I have a user on my linux server who has sudo. I want to edit the crontab of another user. I'm new to this though and don't understand what the man pages are telling me yet. Man crontab tells me I ...
7
votes
3answers
3k views

Is it bad to edit cron file manually?

It is usually instructed to introduce new cron jobs through command lines; but I found it easier (with a better control of current cron tasks) to manually edit (in text editor) the user cron file like ...
7
votes
3answers
4k views

Crond offset five minute schedule

Is it possible to offset a cron script set to run every 5 minutes? I have two scripts, script 1 collects some data from one database and inserts it into another, script 2 pulls out this data and a ...
7
votes
6answers
6k views

crontab environment

I have written various scripts to launch Java server applications, which are typically run for 24 hours before being shut down (by invoking the same script with a different parameter). The script ...
7
votes
2answers
8k views

What user do scripts in the cron folders run as? (i.e. cron.daily, cron.hourly, etc)

If I put a script in /etc/cron.daily on CentOS what user will it run as? Do they all run as root or as the owner?
7
votes
2answers
3k views

Run command as Linux “system” user (shell = /bin/false)

I created a "system" user in Ubuntu 11.04 (adduser --system) for running certain cron jobs, but sometimes I want to test things out by manually running commands as that user. What's the easiest way to ...
7
votes
4answers
1k views

Minutely cron, ensuring only a single instance

Is there a way to run a script every minute (or 2, or 5, etc), but only if it isn't already running? We have a set of scripts that need to run every minute. Sometimes they might start and finish in a ...
7
votes
3answers
1k views

Can I limit the runtime of a cronjob

I've got a cronjob which runs hourly that is occasionally taking too long to run, is there any way I can set a maximum runtime and the job gets killed if it exceeds that? This is on an Ubuntu 10.04 ...
7
votes
7answers
3k views

How to perform cron jobs failover?

Using two Debian servers, I need to setup a strong failover environment for cron jobs that can be only called on one server at a time. Moving a file in /etc/cron.d should do the trick, but is there ...
7
votes
3answers
900 views

What are some ways to prevent user cron jobs from crushing the servers?

It happens fairly frequently that user cron jobs on shared servers all run at the same time and get caught in contention (near as I've been able to tell). So load explodes, Nagios is angry, Apache ...
6
votes
2answers
6k views

How to run cron job on a specific hour every day?

What do I need to write in crontab to execute a script at 3pm every day?