Questions tagged [cron]

Cron is used to execute scheduled commands. It acts as a task scheduler on Linux and UNIX systems which will execute commands at specified times set by the user. Cron has a great deal of customization and is often used on server environments where common tasks are run on a regular basis.

Cron jobs can be set using the crontab -e command. On first run this will invite the user to select an editor for editing cron jobs.

From here, users can input their jobs, each command on a new line, with the desired timing preceding the command. The format for job timing can be used in a variety of ways, from specifying a command to run once a year, to once a minute, or only on Thursdays, etc. There are several examples on the Wikipedia page..

Upon saving the cron file, the crontab command will check the file for syntax errors, and if none are found, save it.

On Ubuntu there are more advanced cron options as well, such as root-level cron and the daily, weekly and monthly cron files. Read more about the specific options on the Cron How to Page.

Common uses of cron are scheduled updates, reboots, and backups. Cron can also be used to filesystem checks and other intense maintenance. Also see Advanced Crontab.

2031 questions
1060
votes
15 answers

Where is the cron / crontab log?

I want to verify that my cron job is executing and at what time. I believe there is a log for my sudo crontab -e jobs, but where? I searched google and found recommendations to look in /var/log (in which I do not see anything with 'cron' in the…
Scott Szretter
  • 10,783
  • 3
  • 15
  • 7
625
votes
8 answers

How do I set up a Cron job?

I want to schedule a task to run on a regular basis and have heard that Cron is the way to do this. How do I add Cron jobs in Ubuntu?
Gabriel Solomon
  • 6,815
  • 5
  • 24
  • 22
618
votes
47 answers

Why crontab scripts are not working?

Often, crontab scripts are not executed on schedule or as expected. There are numerous reasons for that: wrong crontab notation permissions problem environment variables This community wiki aims to aggregate the top reasons for crontab scripts not…
Adam Matan
  • 11,889
  • 22
  • 69
  • 90
314
votes
4 answers

Where is the user crontab stored?

Since upgrading my user's crontab has been wiped out. This is not the first time this has happened this year and it's a pain restoring it each time. I'd like to be able to back up the crontab for my user but for that I need to know where it's…
Oli
  • 282,913
  • 112
  • 661
  • 826
307
votes
13 answers

"(CRON) info (No MTA installed, discarding output)" error in the syslog

I have a fresh install of Ubuntu 12.04.1 LTS an a number of servers. I have not added any cron jobs or edited my crontab on those servers, however, at around the same time for each machine, I get a 75% CPU spike and the following info in my syslog…
sungiant
  • 3,185
  • 2
  • 13
  • 8
180
votes
5 answers

How to run a cron job using the sudo command

Is it possible to run a cron job which needs the sudo command? Like: sudo rm somefile
sayem siam
  • 2,001
  • 2
  • 14
  • 8
177
votes
10 answers

Changing default crontab editor

I am trying to change the default editor from nano to vim. I have run the following commands: sudo update-alternatives --config editor and update-alternatives --config editor Both now output: Selection Path Priority …
austinbv
  • 1,753
  • 2
  • 11
  • 8
120
votes
8 answers

Verify if crontab works

I want to verify if a certain crontab works properly. I have added a job like this: */2 * * * * /path_to_my_php_script/info.php >/dev/null 2>&1 I know that i redirect to the null device, but i not sure if the above command is good. *Edit 1: In my…
croppio.com
  • 1,421
  • 4
  • 13
  • 15
100
votes
2 answers

What is the correct way to edit a crontab file?

I am trying to automate the refreshing of awstats for my webserver and understand that I need to use cron to set that up. So each user has a crontab file? I was following the instructions here community/AWStats And it says to go to the file at:…
timbram
  • 1,775
  • 5
  • 17
  • 20
95
votes
13 answers

How do you set the timezone for crontab?

I have set up ACPI wakeup so my laptop wakes up at a certain time each morning. The timezone for this is UTC. I want to set up my crontabs also using UTC so they fit with the wakeup alarm. How do you do it? I've tried editing /etc/default/cron to…
alj
  • 1,051
  • 1
  • 7
  • 3
82
votes
8 answers

How to run scripts every 5 seconds?

I have a script that needs to be run every five seconds. I know that cron can do tasks by the minute, but is there a way to run something every second?
myusuf3
  • 32,229
  • 40
  • 86
  • 100
77
votes
8 answers

How to remove or delete single cron job using linux command?

I have created cron jobs for my site which is listed below and they are working fine. I print all cron job by using this PHP script: $cronfiles=exec('crontab -l',$output); echo "
";
print_r($output);

Which outputs:

[0] => 0 0 * * * wget php -q…
anumavu
  • 771
  • 1
  • 5
  • 4
72
votes
3 answers

Script doesn't run via crontab but works fine standalone

I have a script that reminds me to restart my computer if uptime is more than, say 3 days (although its set to 0 days now just to check if the script is running as my computer has been up only over a day..). I realize it isn't the most elegant…
dearN
  • 2,099
  • 6
  • 22
  • 32
68
votes
5 answers

Cron.hourly won't run

Ok, So I've made my script, I dropped it in /etc/cron.hourly then I chmod 777 the file but it won't run (automatically). If I manually run it, it works fine. Do I need to do anything else?
Switchkick
  • 3,753
  • 7
  • 32
  • 59
67
votes
6 answers

How to make crontab email me with output?

How can I make crontab email me with the output of its jobs? I have MAILTO=redacted@yahoo.com.au above the jobs, but it doesn't work. I know I need to use something like Postfix or Sendmail but for the life of me I cannot find out how to achieve…
Clonkex
  • 1,436
  • 2
  • 15
  • 18
1
2 3
99 100