Cron is a job scheduler that allows users to run commands periodically.

learn more… | top users | synonyms (1)

45
votes
3answers
5k views

Day of week {0-7} in crontab has 8 options, but we have only 7 days in a week

Day-of-week: Allowed range 0 – 7. Sunday is either 0 or 7. I found this after Googling, my question is why should both values (0,7) correspond to Sunday?
29
votes
14answers
3k views

Run unix command precisely at very short intervals WITHOUT accumulating time lag over time

Question I'd like to be able to run a UNIX command precisely every second over a long time period. I need a solution, which does not lag behind after a certain time, because of the time the command ...
29
votes
8answers
49k views

Where are cron errors logged?

If I setup cron jobs incorrectly they appear to silently fail. Where should I look for an error log to understand what went wrong?
27
votes
1answer
1k views

Why aren't crontabs stored in user home directories?

I'm curious to know: why are crontabs stored in /var rather than in the user's home directories? It makes it a total pain to isolate these files for upgrades but I suspect that there is a logical ...
27
votes
10answers
13k views

Correct locking in shell scripts?

Sometimes you have to make sure that only one instance of a shell script is running at the same time. For example a cron job which is executed via crond that does not provide locking on its own (e.g. ...
27
votes
4answers
20k views

What is the 'working directory' when cron executes a job

I have a script that works when I run it from the command line, but when I schedule it with cron I get errors that it cannot find files or commands. My questions is twofold: When I schedule a cron ...
18
votes
1answer
4k views

How can I execute `date` inside of a cron tab job?

I want to create a log file for a cron script that has the current hour in the log file name. This is the command I tried to use: 0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log ...
17
votes
4answers
800 views

Path independent shebangs

I have a script that I want to be able to run in two machines. These two machines get copies of the script from the same git repository. The script needs to run with the right interpreter (e.g. zsh). ...
16
votes
6answers
29k views

How can I run a cron command with existing environmental variables?

How can I run a cron command with existing environmental variables? If I am at a shell prompt I can type echo $ORACLE_HOME and get a path. This is one of my environmental variables that gets set in ...
15
votes
6answers
565 views

How to Find a Fugitive Crontab

A few years ago I setup a cron job to automatically ping a URL every minute as part of a monitoring system (that's oversimplification, but it'll do for this question). Because I'm a horrible person, I ...
15
votes
6answers
35k views

Why did my crontab not trigger?

I used crontab -e to add the following line to my crontab: * * * * * echo hi >> /home/myusername/test Yet, I don't see that the test file is written to. Is this a permission problem, or is ...
15
votes
2answers
8k views

How can I tell cron to run a command every other day (odd/even)

When configuring cron to run a command every other day using the "Day of Month" field, like so: 1 22 */2 * * COMMAND it runs every time the day of month is odd: 1,3,5,7,9 and so on. How can I ...
14
votes
3answers
924 views

How can I start a cronjob 1 hour later each day?

I need to start a cronjob every day, but an hour later each day. What I have so far works for the most part, except for 1 day of the year: 0 0 * * * sleep $((3600 * (10#$(date +\%j) \% 24))) ...
14
votes
3answers
4k views

Are multiple @daily crontab entries processed in order, serially?

I want two jobs to run sometime every day, serially, in exactly the order I specify. Will this crontab reliably do what I want? @daily job1 @daily job2 I'm assuming they run one after the other, ...
14
votes
2answers
1k views

Origin of the word cron?

Trying to settle a friendly argument. Is "cron" an acronym for something? Additionally, did it's current canonical name "cron" originate from something shortened for something like chronos or ...
12
votes
2answers
41k views

How can get a list of all scheduled cron jobs on my machine?

My sysadmin has set up a bunch of cron jobs on my machine. I'd like to know exactly what is scheduled for what time. How can I get that list?
12
votes
3answers
11k views

Does RHEL execute all cronjob files under /etc/cron.d/*?

This is a RedHat Enterprise Linux 5 system (RHEL). We manage this system using Cfengine. We have several cronjobs which are running twice as often as usual. I checked the cronjobs under /etc/cron.d/ ...
11
votes
3answers
10k views

Manually run a cron job / simulate running cron job?

I am new to cron and I want to test if cron's mailing stuff after an executed task and things like that work. Is there a more elegant way to test this, then setting a cron job to run every few ...
10
votes
6answers
1k views

CronJob every 25 minutes

I want to know whether there is any easier way to run a job every 25 minutes. In cronjob, if you specify the minute parameter as */25, it'll run only on 25th and 50th minute of every hour
10
votes
7answers
5k views

How to restart the Python script automatically if it is killed or dies

I am running my Python script in the background in my Ubuntu machine (12.04) like this - nohup python testing.py > test.out & Now, it might be possible that at some stage my above Python ...
10
votes
1answer
1k views

What does the following kernel message mean?

The following appears /var/log/messages, what that means ? Feb 19 22:51:20 kernel: [ 187.819487] non-matching-uid symlink following attempted in sticky world-writable directory by sh (fsuid ...
9
votes
2answers
1k views

How can I delete all files in a folder that haven't been accessed in a certain amount of time?

I'd like to run a nightly cron job that deletes all the files in a folder that haven't been accessed in a week or more. What is the most efficient way to do this in bash?
9
votes
5answers
5k views

Run a script via cron every other week

I've done quite a bit of research in how to do this, and I see there's no direct way in cron to run a job, say, every other Thursday. Right now, I'm leaning toward making a script that will just run ...
9
votes
4answers
7k views

How do I completely silence a cronjob to /dev/null/?

On my Ubuntu-Desktop and on my debian-server I have a script which needs to be executed each minute (a script that calls the minute-tic of my space online browsergame). The problem is that on ...
9
votes
5answers
20k views

Using the system date / time in a Cron Script

I'm setting up a Cronjob that will backup a MySQL database I have in my server, but I don't want it to keep overwriting the same file over and over again. Instead, I want to have an array of backups ...
9
votes
1answer
192 views

Cronjob to Run and then Terminate

I want to add a cron entry that does something like: 00 00 * * * * /tmp/script.sh Is there something I can add to the end of the line, so that when it is finished, it will remove the line out of my ...
9
votes
1answer
15k views

How to redirect output to a file from within cron?

I have a backup script which I need to run at a particular time of a day so I am using cron for this task and from within cron am also trying to redirect the output of backup script to a logfile. ...
9
votes
1answer
8k views

Cron log on debian systems

On Redhat systems cron logs into /var/log/cron file. What is the equivalent of that file on Debian systems?
9
votes
1answer
107 views

Finding which cron jobs are scheduled to run at some future date/time X

Is there a way to "query" a crontab to find which cron jobs run at some arbitrary date/time, or during a certain range of times? For example, determine which will be run at sometime between 14:00 and ...
8
votes
2answers
7k views

Bash Script on Startup? (Linux)

Is there any way to make/run a bash script on reboot (like in Debian/Ubuntu for instance, since thats what my 2 boxes at home have) Also, any recommended guides for doing cron jobs? I'm completely ...
8
votes
1answer
2k views

How do I enable locate and queue the database to be built?

On a new Ubuntu 10.4 instance, I tried to use the locate command only to receive the error locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory from using this command ...
8
votes
2answers
665 views

Interactive shell with environment identical to cron

I am aware of a lot of pitfalls in the magic world of crontabs, but sometimes it would help troubleshooting a lot when you have some smart way to enter an interactive (bash) shell with exact identical ...
8
votes
1answer
7k views

how can I make cron run a job right now, for testing/debugging? without changing the schedule!

I have a cron job that is scheduled to run everyday, other than changing the schedule, is there any other way to do a test run of the command right now to see if it works as intended?
8
votes
1answer
983 views

Suppress output unless non-zero exit code

What's the best way to suppress output (stdout and stderr) unless the program exits with a non-zero code? I'm thinking: quiet_success() { file=/tmp/suppressed if ! ( "$@" > "$file" ...
7
votes
7answers
2k views

cron Vs. sleep - which is the better one in terms of efficient cpu/memory utilization?

The Case: I need to run some commands/script at certain intervals of time and for this I have two options - 1. set up a cron-job or, 2. implement a loop with sleep in the script itself. Question: ...
7
votes
3answers
10k views

Cron running job every 15 seconds

Could you advise me what to write in crontab so that it runs some job (for testing I will use /usr/bin/chromium-browser) every 15 seconds?
7
votes
3answers
1k views

Run Script once a day with systemd

I want to run a backup script 10 minutes after booting up my machine but only once a day. Is it possible to build up such scenarios with systemd?
7
votes
1answer
2k views

List of modified files of the past 24 hours

Is there a reliable way to have a system that mails me the list of files that were modified in the past 24 hours inside a set of directories? (like /home/*/public_html/* and /home/*/*domains/*)
7
votes
3answers
8k views

/etc/cron.daily/foo : Send email to a particular user instead of root?

I'm running CentOS 5.5. We have several cronjobs stored in /etc/cron.daily/ . We would like the email for some of these cronjobs to go to a particular email address, while the rest of the emails in ...
7
votes
5answers
5k views

Run script in a non interactive shell?

I have a cron job that is running a script. When I run the script via an interactive shell (ssh'ed to bash) it works fine. When the script runs by itself via cron it fails. My guess is that it is ...
7
votes
1answer
521 views

How to autostart a background program by a non-root user?

As a non-root user, I want to run a background job when the system boots. It's sort of a service which doesn't require root privilege. Is there a way to do it? One way is to put sudo -u user command ...
6
votes
1answer
3k views

Meaning of “* */1 * * *” cron entry?

Somehow, I am finding it difficult to understand tweaking around * parameters with cron. I wanted a job to run every hour and I used the below setting: * */1 * * * But it does not seem to do the ...
6
votes
1answer
7k views

Why does cron silently fail to run sudo stuff in my script?

I have a script run from a non-privaleged users' crontab that invokes some commands using sudo. Except it doesn't. The script runs fine but the sudo'ed commands silently fail. The script runs ...
6
votes
3answers
657 views

sort at jobs chronologically

Possibly a simple solution I misplaced. How can I get the output of atq sorted chronologically, so I can easily see who's due to run next? The man page for sort doesn't have anything built-in to ...
6
votes
2answers
4k views

Can I automate tar's multi-volume-feature?

Ok, so I've just had a read through this page after a way to improve my current backup solution on my Debian server. Tar seems to be offering a quite nice multi-volume feature, although when I try it ...
6
votes
1answer
2k views

What's the meaning of the slash in crontab?

I have seen a crontab record in system. 0-55/5 * * * * root <command> I read the crontab -e example files and I know the first position stands for minute. But I cannot figure out the ...
6
votes
1answer
330 views

Recover cron jobs accidently removed with crontab -r

I entered crontab -r instead of crontab -e and all my cron jobs have been removed. What is the best way (or is there one) to recover those jobs?
6
votes
1answer
2k views

How to change cron shell (sh to bash)?

Is it possible to make commands in crontab run with bash instead of sh? I know you can pass commands to bash with -c, but that's annoying and I never use sh anyway.
6
votes
2answers
2k views

Logging ALL stderr output of crontab to file

For example, I can log stderr of one script in this way: * * * * * run_script.sh > /var/log.txt 2>&1 But I want to log stderr of all scripts in my crontab. I can append > /var/log.txt ...
6
votes
2answers
6k views

Can I change the default mail recipient on cron jobs?

I believe that if there is any output from a cronjob it is mailed to the user who the job belongs to. I think you can also add something like MAILTO=vivek@nixcraft.in at the top of the cron file to ...