Questions tagged [cron]

Cron is a job scheduler that allows users to run commands periodically.

Cron is a daemon that runs periodic scheduled jobs.

Use the crontab command to edit the table of scheduled jobs.

Use to schedule a job for one execution only at a specific date.

Common pitfalls

If a command works when you type it in a terminal but not from a crontab, here are some common reasons:

  • Cron provides a limited environment, e.g., a minimal $PATH.

    • Try adding this entry to your crontab to see what cron's environment is:

      * * * * * { date; pwd; echo "env:"; env; echo "set:"; set; } > ~/cron.env 
      
  • Cron uses /bin/sh, which may not be the shell you normally use.

  • Cron treats the % character specially (it is turned into a newline in the command).

    • This will affect the date command especially:

      * * * * * date "+%F %T"     # bad: cron sees `date "+`
      * * * * * date "+\%F \%T"   # good
      

Further reading

2338 questions
176
votes
6 answers

What does '>/dev/null 2>&1' mean in this article of crontab basics?

I am reading an article about crontab There is something about disabling automatically sending emails. Disable Email By default cron jobs sends an email to the user account executing the cronjob. If this is not needed put the following command…
AGamePlayer
  • 7,605
104
votes
6 answers

As root, how can I list the crontabs for all users?

I have a script being run automatically that I can't find in the crontab for the expected users, so I'd like to search all users' crontabs for it. Essentially I want to run a crontab -l for all users.
68
votes
5 answers

How can I tell cron to run a command every other day (odd/even)

When configuring cron to run a command every other day using the "Day of Month" field, like so: 1 22 */2 * * COMMAND it runs every time the day of month is odd: 1,3,5,7,9 and so on. How can I configure cron to run on days of month that are even…
freddie
  • 683
48
votes
1 answer

How are files under /etc/cron.d used?

How are files under /etc/cron.d used? From https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/ cron reads the files in /etc/cron.d/ directory. Usually system daemon such as sa-update or sysstat places their cronjob…
Tim
  • 101,790
47
votes
2 answers

What's the meaning of the slash in crontab?

I have seen a crontab record in system. 0-55/5 * * * * root I read the crontab -e example files and I know the first position stands for minute. But I cannot figure out the meaning of / (slash) there. Could anyone explain the meaning…
steveyang
  • 1,121
37
votes
2 answers

Is a restart of cron or crond necessary after each new schedule addition or modification?

When I schedule a job, some seem to be applied immediately, while others after a reboot. So is it recommended to restart cron (crond) after adding a new cron job? How to do that properly (esp. in a Debian system), and should that be done with sudo…
rusty
  • 1,881
31
votes
2 answers

Do spaces matter in a crontab

It's not clear to be from the manpage for crontab. IS extra white space allowed between the fields? e.g., if I have this: 1 7 * * * /scripts/foo 5 17 * * 6 /script/bar 31 6 * * 0 /scripts/bofh is it safe to reformat it nicely like this: 1 7 * * *…
BIBD
  • 415
30
votes
8 answers

Why did my crontab not trigger?

I used crontab -e to add the following line to my crontab: * * * * * echo hi >> /home/myusername/test Yet, I don't see that the test file is written to. Is this a permission problem, or is crontab not working correctly? I see that the cron process…
ripper234
  • 31,763
26
votes
4 answers

Crontab entry with hour range going over midnight

Is this valid crontab time specification, doing what is expected: 0 22-4 * * * Or is it necessary to do something like 0 22,23,0,1,2,3,4 * * *
hyde
  • 1,288
  • 1
  • 13
  • 20
22
votes
7 answers

Crontab error: no crontab For [user]

I'm seeing an error every time I do the command below. Why? $crontab -l no crontab for server where server is the user account. This issue comes about because the script in crontab doesn't work, so I've tried to break down the problem. This is what…
22
votes
1 answer

Does a job scheduled in crontab run even when I log out?

I add some job in crontab file on a server. When I log out and the server is still on, will the job still run? Does it matter if I create a screen or tmux session and run some shell in it and detach it before log out?
Tim
  • 101,790
22
votes
6 answers

how to temporarily disable a user's cronjobs?

How do I temporarily disable one or more users' cron jobs? In particular, I do not want to suspend the user's cron rights - merely not fire any of their jobs. I am on SLES 11 SP2 and SP3 systems
Dinesh
  • 1,291
22
votes
4 answers

Cron running job every 15 seconds

Could you advise me what to write in crontab so that it runs some job (for testing I will use /usr/bin/chromium-browser) every 15 seconds?
xralf
  • 15,415
21
votes
4 answers

Run multiple cron jobs where one job takes a long time

I have the following general question regarding cron jobs. Suppose I have the following in my crontab: * 10 * * * * someScript.sh * 11 * * * * someScript2.sh 30 11 */2 * * someScript3.sh <-- Takes a long time let's say 36 hours. * 12 * * *…
21
votes
2 answers

Can grep | crontab destroy all jobs?

My colleague ran grep | crontab. After that all jobs disappeared. Looks like he was trying to run crontab -l. So what happened after running the command grep | crontab? Can anyone explain?
1
2 3
20 21