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.

2150 questions
642
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?
632
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
  • 12,519
340
votes
14 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,515
337
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
  • 293,335
207
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,291
129
votes
9 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,509
119
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,995
95
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
  • 951
  • 1
  • 7
  • 4
74
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,179
61
votes
6 answers

How to set up a root cron job properly

I tried to set up a root cron job to run a Bash script as root, to run at minute 7,37, every hour, every day of month, every month. This script is located in /usr/bin and named tunlrupdate.sh. It updates the DNS of Tunlr. $ ls -l…
Antonio
  • 1,594
43
votes
3 answers

"command not found" when running a script via cron

I want to run my script in crontab, but I have some problems... In my script I run this command: db2 connect to myDB2 This works fine when I run this as db2inst1 user, but when I run this script in db2inst1 crontab, I get this: db2: command not…
Wolfy
  • 7,920
36
votes
2 answers

Running command at startup on crontab

I wanted to run a command on our linux after its done rebooting, I saw that it can be done using crontab. I wanted to run this command sudo ifdown eth0 && sudo ifup -v eth0 on the crontab can i just do: @reboot sudo ifdown eth0 && sudo ifup -v…
Lottie
  • 393
32
votes
3 answers

Does Ubuntu support "@reboot" in crontab?

Does Ubuntu support @reboot in crontab? I find documentation suggesting it is supported, but web chatter asserts it is not. I cannot make the @reboot section work. The "after midnight" section works fine. Here is the test example from my…
user186171
  • 321
  • 1
  • 3
  • 3
20
votes
4 answers

Ubuntu auto delete oldest file in directory when disk is above 90% capacity, repeat until capacity below 80%

I have found a few similar cron job scripts but nothing exactly how I need them and I do not know enough about scripting for Linux to try modify the code when it comes to this sort of job which could turn disastrous. Essentially I have ip cameras…
Beno
  • 301
16
votes
1 answer

Crontab syntax; Multiple commands

I would like to get the following chain of commands as a cronjob: * * * * * source activate myenv3 && cd ~/foo/bar && python sssb.py It works in console, but I dont get any output from the cronjob. I followed this suggestion, by replacing it with…
FooBar
  • 643
1
2 3
20 21