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.
1,966
questions
395
votes
7
answers
970k
views
Why is my crontab not working, and how can I troubleshoot it?
This is a Canonical Question about using cron & crontab.
You have been directed here because the community is fairly sure that the answer to your question can be found below. If your question is ...
255
votes
10
answers
327k
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 ...
166
votes
14
answers
561k
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 ...
163
votes
12
answers
332k
views
Best practices for setting a cron job for Let's Encrypt (Certbot) renewal?
Is this correct way to set cron for renewal of Let's Encrypt cert in Apache2 ?
I use Ubuntu 16.04.
@monthly letsencrypt renew && service apache2 reload
150
votes
5
answers
94k
views
Job scheduling using crontab, what will happen when computer is shutdown during that time?
I schedule some tasks using crontab.
What will happen if my computer is shutdown or turned off during the time when cron was scheduled to do something?
Does each missed cron job run after computer ...
128
votes
11
answers
91k
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 ...
111
votes
6
answers
405k
views
how to create a cron job that runs on the first day of month [duplicate]
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?...
106
votes
2
answers
48k
views
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 ...
101
votes
10
answers
251k
views
How to disable everything in crontab -l?
I just want to pause everything. Don't execute anything listed on crontab -l.
83
votes
3
answers
152k
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 all-...
82
votes
4
answers
153k
views
Running Cron every 2 hours [duplicate]
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
77
votes
4
answers
196k
views
What is the correct syntax to run cron every 4 hours? [duplicate]
I have the following syntax (which I think is correcT?) but it runs the command every minute!
* */4 * * * /cmd.sh
75
votes
2
answers
106k
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 ...
74
votes
5
answers
136k
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?
73
votes
6
answers
166k
views
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 ...
72
votes
5
answers
74k
views
How to send the output from a cronjob to multiple e-mail addresses?
In the beginning of a crontab file you could 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 ...
70
votes
3
answers
57k
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 ...
67
votes
3
answers
206k
views
php cli memory limit
I am getting a memory error in a php cron job:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /opt/matrix/core/lib/DAL/DAL.inc on line 830
The ...
67
votes
3
answers
304k
views
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 ...
65
votes
10
answers
74k
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?
64
votes
7
answers
92k
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 ...
63
votes
2
answers
123k
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?
62
votes
4
answers
49k
views
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 ...
62
votes
2
answers
65k
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?
61
votes
6
answers
36k
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:
...
57
votes
3
answers
128k
views
Do I need to refresh or restart anything after I add/update a crontab in Ubuntu Server 8.04?
When you change something in Apache you need to reload or restart apache. Does anything need to be refreshed or restarted in Ubuntu Server 8.04 after I add/update the crontab? Thanks a bunch for your ...
56
votes
6
answers
74k
views
Cron: Only get errors in emails?
I finally set up a realistic backup schedule on my data through a shell script, which are handled by cron on tight intervals. Unfortunately, I keep getting empty emails each time the CRON has been ...
56
votes
4
answers
114k
views
how to run cron job every 3 months?
What would be the crontab entry look like for a job that runs on the first day of every third month?
54
votes
4
answers
238k
views
How to check cron logs in Ubuntu
I went to /var/log/cron but this file is empty.
How to check if crontab is enabled or is running properly or not in ubuntu
thanks
54
votes
7
answers
122k
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 ...
52
votes
4
answers
37k
views
Should I edit /etc/crontab or run crontab -e as root?
I'm setting up regular system maintenance tasks which have to run as root. I plan to use the flavour of cron which comes with Ubuntu 14.04 LTS as the default.
I see the previous admin (who since left ...
47
votes
13
answers
72k
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 [email protected].
How could I change it to something like [email protected]?
44
votes
4
answers
13k
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 [email protected] -s "query for `date +%Y-%m-%dZ%I:%M`"
Here's the error message:
/bin/sh: -c: line 0: ...
44
votes
5
answers
272k
views
How to save and exit crontab -e?
How to save and exit crontab -e?
i tried every method listed here and none works, i have a centos 5, vi comes by default with yum and i installed nano
Solved
just changed the default editor
export ...
43
votes
6
answers
50k
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 /...
43
votes
1
answer
62k
views
Can you have a multi-line comment a crontab
Can I use the C++/Java-style /* */ syntax to multi-line comments in the crontab file?
41
votes
2
answers
33k
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 ...
40
votes
4
answers
86k
views
How To Backup "crontab -e" Files?
I want to do a complete server backup.
I already have my backup script copying all of the html/php files for the web app, and the mysql databases, placing them into a .tar.gz file.
How can I add the ...
36
votes
16
answers
51k
views
Can't run AWS CLI from CRON (credentials)
Trying to run a simple AWS CLI backup script. It loops through lines in an include file, backs those paths up to S3, and dumps output to a log file. When I run this command directly, it runs without ...
33
votes
4
answers
75k
views
crontab execution doesn't have the same environment variables as executing user
I ran my crontab job 0 2 */1 * * /aScript >aLog.log 2>&1 as a 'root' user, and however I found the env is different from env of the 'root' user, and therefore experiencing a different ...
33
votes
8
answers
28k
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 ...
32
votes
8
answers
30k
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 ...
32
votes
7
answers
61k
views
How to change the time cron.daily is run in linux
I have a script in cron.daily that runs at a certain time every morning. I need to change the time that it is run.
How do I change the time cron.daily runs the scripts?
32
votes
1
answer
46k
views
What's the difference between /etc/cron.d and /var/spool/cron?
The crontabs on RHEL seem to be duplicated in two places, /etc/cron.d, and /var/spool/cron. I've checked, and neither of these are simlinks to the other, and neither are any of the crons contained in ...
31
votes
2
answers
5k
views
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 ...
31
votes
6
answers
7k
views
Outgrowing cron: what's the next scheduler? [closed]
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 ...
30
votes
4
answers
103k
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 /var/spool/cron/...
28
votes
2
answers
20k
views
Crontab maximum command length
Is there a limit of characters a command in a crontab could be ?
I have a crontab with a 178 characters command and it seems to be truncated at 164 when executed. I can tell this number from the e-...
27
votes
5
answers
30k
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 ...
27
votes
2
answers
125k
views
How to configure cron job to run every 2 days at 11PM [duplicate]
I have a centos server and I want to run a job on it at 11PM every 2 days, how do I do that?