Questions tagged [cron]

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.

For information about the most common cron issues and how to fix them, see Why is my crontab not working and how can I troubleshoot it.

1964 questions
166
votes
14 answers

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 cronned. I am aware that I can set up a * * * * *…
Pistos
  • 3,153
112
votes
6 answers

how to create a cron job that runs on the first day of month

There are fields on my server's control panel like this Minute - Hour - Day of month - Month - Day of the week - Command How can I create a cron job runs on first day of the month with this fields?
Utku Dalmaz
  • 1,369
  • 2
  • 14
  • 18
106
votes
2 answers

escaping double quotes and percent signs (%) in cron

The following command works from prompt but not from crontab. grep abc /var/log/messages | grep "`date '+%B %d'`" | mail -s"abc log of `hostname`" s.o+`hostname`@gmail.com I need to add it to daily cron.
shantanuo
  • 3,619
77
votes
4 answers

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
erotsppa
  • 2,163
73
votes
6 answers

Sending cron output to a file with a timestamp in its name

I have a crontab like this on a LAMP setup: 0 0 * * * /some/path/to/a/file.php > $HOME/cron.log 2>&1 This writes the output of the file to cron.log. However, when it runs again, it overwrites whatever was previously in the file. How can I get cron…
67
votes
3 answers

crontab running as a specific user

I need to run a script daily. The script should be run as a specific user (ex. user1) not as root. So I put the cron file at /etc/cron.d and put the user name in the line (2nd column). But it gives an error saying that the command is not found. I…
Sam Kong
  • 933
64
votes
7 answers

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 save, unlike crontab -e -- so a stray character can…
Ben K.
  • 2,439
62
votes
2 answers

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?
Kyle MacFarlane
  • 817
  • 2
  • 9
  • 12
62
votes
4 answers

How to: 1 Cron Job every ODD minutes and 1 other every EVEN minutes?

I have 2 cron jobs, i want one of them to run every odd minute (1,3,5,7,9,11....57,59) and i want the other one to run every even minute (0,2,4,6,8,10,12...58) how can i do it in an easy way? (no scripting - just cron job rules)
wabbajay
  • 629
31
votes
2 answers

Why did my cron job run this month?

Today is November 1st 2016 or in (unambiguous) numerals, 2016-11-01. I have a user cron job set up like this: # m h dom mon dow command 33 3 1 */2 * /home/user/... It is supposed to run every other month on the first of the month at…
comfreak
  • 1,531
  • 1
  • 21
  • 35
30
votes
4 answers

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 /var/spool/cron/crontabs ls: cannot open directory…
Nick Bolton
  • 5,146
27
votes
5 answers

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 lot of other data and creates some pretty reports…
user80776
21
votes
3 answers

Cron expression: difference between 0/1, 1/1 and *

In a cron expression, what is the difference between 0/1, 1/1 and * ?
sdabet
  • 333
21
votes
4 answers

Running cron every 10 minutes

I have a python script on my desktop: /home/ceasor/Desktop/script.py In /etc/crontab, I wrote: 0 */2 * * * ceasor sudo python /home/ceasor/Desktop/script.py The python script is not getting run. How do I run cron every 10 minutes?
ceasor
19
votes
4 answers

How to run a cron job only once?

I have a job which runs forever the moment it starts. So i want to start it only once after entering it into "crontab -e" file and saving it (or) whenever reboot happens. How to achieve this?
1
2 3
15 16