Cron is a job scheduler that allows users to run commands periodically.
26
votes
12answers
2k 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 ...
20
votes
7answers
18k 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?
20
votes
6answers
6k 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. ...
13
votes
5answers
464 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 ...
12
votes
3answers
2k 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, ...
11
votes
4answers
3k 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 ...
11
votes
2answers
555 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 ...
10
votes
3answers
6k 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/ ...
9
votes
2answers
771 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
1answer
770 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 ...
8
votes
6answers
711 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
8
votes
6answers
17k 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 ...
8
votes
1answer
1k 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
...
8
votes
1answer
618 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
2answers
3k 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 ...
7
votes
2answers
250 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 ...
7
votes
3answers
10k 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 ...
6
votes
2answers
3k 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 ...
6
votes
4answers
3k 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 ...
6
votes
2answers
10k 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?
6
votes
3answers
325 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
1answer
1k 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/*)
6
votes
2answers
909 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
2k 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 ...
5
votes
1answer
577 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 ...
5
votes
2answers
576 views
Open emacs in a terminal when editing crontab
I have setup emacs as my default editor in /etc/profile. When I want to use emacs in a terminal. I open it with the -nw option. How can I have the same behavior when doing a crontab -e preventing it ...
5
votes
2answers
2k 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 ...
5
votes
3answers
4k 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 ...
5
votes
2answers
591 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?
5
votes
1answer
630 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 ...
5
votes
3answers
1k views
Frustrating issue where neither cron nor su -c runs my job (permissions?)
Updated (and snipped) with more details below.
I've set up a cron script and I'm trying to debug why it's not running. [Snipped context testing, which is all ok; see revision 2 for details] The ...
5
votes
4answers
2k 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 ...
5
votes
2answers
3k 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 ...
5
votes
2answers
786 views
Automatic security updates on Debian squeeze server
For a production Debian squeeze server, what are the best practices or recommendations for handling security updates? I have seen various articles on cron-apt, apticron, unattended-updates, apt cron ...
5
votes
2answers
473 views
What could cause a cron to run twice at the same moment?
I have a cron that is setup to run every Monday at 1 AM
0 1 * * 1 /script/dir/script >> /script/dir/file.log
After two years of running as expected, it ran twice on June 18, with the second ...
5
votes
1answer
252 views
Run script when specific users logout
I need to run my application in screen when specific users are logged out and kill the screen when someone from my user list logged in. So I am thinking about bash script, which will be called ...
5
votes
1answer
570 views
Running cron script with lynx fails to work
I'm trying to automate a login process that can only be done through a browser. I am using the lynx browser to script the actions required to do this. Lynx does this by dumping a user's keystrokes ...
4
votes
2answers
1k views
Cronjob to run every 30 minutes
I want to set a cronjob entry that runs a script every 30 minutes from 9:00 to 18:00 but I do not want it to run at 18:30. The script should run for the first time at 9:00 and for the last time at ...
4
votes
2answers
200 views
cron every X exact meaning
In cron you can specify */n where n means every n times period, for instance in the first column is minute.
*/5 means every 5 minutes, but which minutes? 0, 5, 10, ...?
What happens if the number ...
4
votes
3answers
694 views
How can I ensure my cronjob will run at specified time?
I'd like to know how I can check to see if my cronjob will run at the specified time I set it at. Is there anyway I can test this without having to wait for that time?
Here are my crontab -l results:
...
4
votes
3answers
213 views
What's the purpose of having different crontabs per user?
Is it just for controlling the permissions of the script being called or does it also effect when or if the script runs? I assume if I setup a cron for a non-root user it should always run, even if I ...
4
votes
3answers
128 views
How to get which version of cron daemon is running
Background: I am working on CentOS
Details
# cat /proc/version
Linux version 2.6.18-308.4.1.el5PAE (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Tue Apr 17 ...
4
votes
3answers
854 views
Check if script is started by cron, rather than invoked manually
Is there any variable that cron set when it's running a program ? If the script is running by cron, I'll skip some parts; otherwise invoke those parts.
How can I know if the bash script is started by ...
4
votes
3answers
744 views
In linux, would it be possible to run a script every day 3 minutes later than the previous day?
My first solution to this was to execute date +%Y%m%d%H%M and put that format of numbers into a file, and run the script every minute from cron. Then if the date from the file matches the date ...
4
votes
2answers
448 views
/etc/crontab permissions
The /etc/crontab file has the permissions:
-rw-r--r--
I understand that this file is for system cron jobs and other users should not have permission to modify it. The current permissions allows all ...
4
votes
3answers
3k views
How to add unique id to file name in cron job?
My cronjob looks like this:
5 3 * * * mysqldump -u root test > /srv/backup/mysql_daily.dump
How can I make filename unique for every time when cronjob writes mysql_daily.dump?
4
votes
3answers
4k 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?
4
votes
1answer
110 views
In crontab is it possible to specify a user from a variable?
I am trying to have the following cron executed with a certain user.
U=`/usr/bin/w | grep -w :0 | awk '{ print $1 }'`
*/1 * * * * $U /opt/script.sh
It seems the deamon doesn't know how to interpret ...
4
votes
3answers
477 views
Crontab job not emailing on failure
I have a cron job on Debian:
1 * * * * /home/paradroid/bin/myscript.sh >/dev/null
There is an installed and configured MTA, and I have received emails when the script has a syntax error, so I ...
4
votes
5answers
9k 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 ...