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.

1957 questions
52
votes
4 answers

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 the company) edited /etc/crontab directly.…
marcv81
  • 632
  • 1
  • 5
  • 7
45
votes
13 answers

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?
Alexander Artemenko
  • 1,393
  • 3
  • 13
  • 13
43
votes
4 answers

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: unexpected EOF while looking for matching ``' /bin/sh: -c:…
Terry G Lorber
  • 667
  • 2
  • 9
  • 14
43
votes
6 answers

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 /var/log/syslog: Jun 25 00:56:01 myhostname…
user7321
  • 1,016
  • 1
  • 9
  • 13
43
votes
5 answers

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 EDITOR=nano and now i can do what I do using nano…
user
  • 849
  • 3
  • 13
  • 18
43
votes
1 answer

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?
belaz
  • 595
  • 1
  • 5
  • 7
40
votes
2 answers

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 do this? su doesn't work, because the user has…
EMP
  • 5,172
  • 10
  • 37
  • 33
39
votes
4 answers

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 crontab files to that backup? Whenever I save the…
darkAsPitch
  • 1,931
  • 4
  • 25
  • 42
36
votes
16 answers

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 any error. When I run it through CRON I get an…
binaryorganic
  • 6,021
  • 4
  • 18
  • 19
33
votes
4 answers

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 runtime behavior of my scripts. An attempt fix was placing export…
Bamboo
  • 435
  • 1
  • 4
  • 8
32
votes
7 answers

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?
Phil_Parnili
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,501
  • 1
  • 21
  • 33
31
votes
8 answers

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 ignorant and don't put in those redirects; in this case the output…
Brad
  • 412
  • 1
  • 4
  • 7
30
votes
6 answers

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 monitoring checks are scheduled across a few…
Cakemox
  • 25,209
  • 6
  • 44
  • 67
30
votes
8 answers

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 script' functionality. Obviously, simply…
benizi
  • 452
  • 1
  • 5
  • 7