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

learn more… | top users | synonyms (1)

46
votes
3answers
6k 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?
32
votes
8answers
55k 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?
30
votes
14answers
4k 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 ...
30
votes
4answers
23k 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 ...
29
votes
10answers
15k 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
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 ...
21
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 ...
19
votes
8answers
32k 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 ...
18
votes
4answers
833 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). ...
15
votes
6answers
580 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
3answers
970 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))) ...
15
votes
6answers
37k 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
9k 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
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 ...
13
votes
2answers
48k 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
12k 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
4answers
13k 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 ...
11
votes
5answers
21k 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 ...
11
votes
3answers
11k 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
2k 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
6k 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
18k 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. ...
10
votes
1answer
8k 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?
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
1answer
3k 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 ...
9
votes
1answer
200 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
9k 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
149 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
2answers
727 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
1k 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
2answers
5k views

cron ignores variables defined in “.bashrc” and “.bash_profile”

I have defined "SHELL" variable in /etc/crontab file: [martin@martin ~]$ grep SHELL /etc/crontab SHELL=/usr/local/bin/bash [martin@martin ~]$ file /usr/local/bin/bash /usr/local/bin/bash: ELF 32-bit ...
7
votes
3answers
2k views

Using notify-send with cron

I am using Arch Linux with KDE/Awesome WM. I am trying to get notify-send to work with cron. I have tried setting DISPLAY/XAUTHORITY variables, and running notify-send with "sudo -u", all without ...
7
votes
3answers
12k 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
1answer
8k views

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

I have a script run from a non-privileged 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 ...
7
votes
3answers
2k 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
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 ...
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
1answer
3k 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.
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
2answers
9k views

crontab's @reboot only works for root?

man 5 crontab is pretty clear on how to use crontab to run a script on boot: These special time specification "nicknames" are supported, which replace the 5 initial time and date fields, and ...
7
votes
1answer
602 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
2answers
5k views

Not able to ssh in to remote machine using shell script in Crontab

Below is the script which i am trying to run, which runs without any issue for i in `seq 200 2100` do usr=(`ssh -t -t -o ConnectTimeout=60 machine$1 finger | tail -1 | awk '{print$1}'`) echo ...
6
votes
3answers
721 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 ...