in the logrotate manpage, they say:
"Normally, logrotate is run as a daily cron job".
Does that mean that logrotate uses cron (or is executed by cron)?
If so, does that mean that if I don't configure a cron job via crontab (for instance), logrotate will not work?
You CAN run logrotate manually WITHOUT cron.
logrotate <configuration file>
However if you want to run logrotate on a scheduled basis, yes you will need cron.
Your package manager should create a default schedule in /etc/cron.daily/logrotate that runs logrotate with the default /etc/logrotate.conf configuration. You can also place your custom configurations in /etc/logrotate.d/ since the default configuration has a line that include all configurations in this directory.
include /etc/logrotate.d
If you want to run logrotate with a custom schedule, you can place your cron job in /etc/cron.d/.
For example, this would trigger logrotate using /etc/custom-logrotate.conf configuration every day at two o'clock.
0 2 * * * root /usr/sbin/logrotate /etc/custom-logrotate.conf
Checkout crontab guru if you need help with cron expression.
Yes, normaly, cron executes logrotate on a daily base.
I depends on your linux distro, but the normal is to have cron running it.
You can check if have the file /etc/cron.daily/logrotate
If thats the case, you distro uses cron to run logrotate.
If you are using docker, this can bring some problem, currently cron doesn't run inside a container.
Related
I have set up cron jobs for my SugarCRM as requested by Sugar:
But when we look at last runs it does not seem to work or show anything.
I am using this for email reminders, mail check and also scheduled campaign run.
Is command-line php on your system installed and the executable in whatever PATH that cronjob is using?
If not make sure to specify the full path, e.g. /usr/bin/php or /usr/local/bin/php are common.
Also based on your operating system/distribution the php command line executable may have a different name, e.g. php5.
Make sure to use the web-process user's crontab or execute php with sudo -u webprocessusername, so that the cronjob will be executed with the correct permissions.Running the cronjob as different user or even root is usually not a good idea.
To see potential error messages replace > /dev/null e.g. with > /tmp/sugarcron.log or > /path/to/webfolder/sugarcron.txt and check the file after a minute.
Further info on the SugarCRM Knowledge Base:
Introduction to Cron Jobs
Troubleshooting Cron and Schedulers
I have a gentoo Linux system and a strange behavior of crontab. As root user, and as I understand the documentation, the command
crontab -l
lists all crontab jobs defined for the current user, root (There are no cronjobs defined for any other used). All listed cronjobs are also defined in the file /etc/cronjob.
However, there are two more crontab files located in /etc/cron.d, which define a cronjob each:
/etc/cron.d/testcron1
/etc/cron.d/testcron2
Although not listed with crontab -l, the cronjob defined in the file /etc/cron.d/testcron1 is executed. The other cronjob defined in the file /etc/cron.d/testcron2 is NOT executed.
This all does not make sense, so I have two questions:
Why does crontab -l list not all cronjobs?
Must the cronjobs in /etc/cron.d be registered somewhere, or is a restart of a daemon/service required? Why is the one started, and not the other one (the executable works fine, though).
The command crontab is used to maintain/manage crontab files for individual users. These files are usually located in /var/spool/cron/crontabs.
If crontab -l dose not show any cron jobs then this user currently has no individual cron jobs. This dose not mean that there are no cron jobs in /etc/cron* taht will run with the privileges of this user. crontab will not operate on the files in /etc/cron*. It is a tool for only managing individual (per user) cron jobs held in /var/spool/cron/crontabs.
Now lets see how the different cron jobs get executed.
Form the manpage of the cron daemon we can read:
cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); ...
cron also reads /etc/crontab, which is in a slightly different format (see crontab(5)).
as well as:
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...
(I think this applies to gentoo as well...)
About restarting we can read:
cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute...
Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on the /etc/crontab file) has changed, and if it has, cron will then examine the modtime on all crontabs files and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note
that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.
So the crontab command is for user specific corn jobs while the files in /etc/cron* are more for system cron jobs.
No manual triggering is needed to activate a new cron job.
I can't seem to run cron jobs and I can't figure out why. I'm new to this so I might be making an amateur mistake.
First, I create a script and call it 'test.sh', putting it in the /usr/local/bin folder. The script contains:
#!/bin/bash
echo "This test works!"
Next, I create a file called 'randomtest' in the /etc/cron.d folder. The file contains:
00 09 * * * root /usr/local/bin/test.sh >> /var/log/test.log
I expect the cron job to run at 9:00 AM every day, but for some reason, it doesn't. I also don't get a log file as expected. I checked the permissions on the test.sh file and it's currently set to 755, which should work.
Is there something I'm doing wrong? Am I missing a crucial element? Do I need to add my 'randomtest' file to the crontab or something?
Reload the cron daemon by using /etc/init.d/crond reload.
(Even if it's already running!)
The problem is that you're messing around with the /etc/cron.d directory rather than using the crontab command.
Unless you definitely need a cron job to run as root, just add it to your own crontab using the crontab command. You can use crontab -e to edit it, but it's better to keep your own copy of your crontab (ideally under version control) and use the crontab filename version of the command to install it. This ensure that the cron daemon will be aware of the update, and that any syntax errors will be caught. It also means you don't need to run any commands as root; avoiding root commands unless they're actually necessary is always a good idea.
Note that system crontabs (those in /etc/crontab and under the /etc/cron.d directory -- though those locations are implementation details that you ideally shouldn't have to worry about) have a different syntax than user crontabs; each line has an extra field that specifies the account under which the commans is to be run.
If you need a command to run as root, you can either update a system crontab file (carefully!), or you can set up a user crontab for the root user, using the normal crontab command as you would for any user account.
Is it possible to run a cron job on host that also saves a file to your website directory? I have an API I download a xml file from hourly. I would like to schedule cron to automate this but I'm not sure if it's possible.
You can write a cron job to execute an arbitrary script. The script can do whatever you like provided it has the appropriate permissions.
* * * * * /bin/execute/this/script.sh
Will run the script script.sh
You need to configure the crontab entry appropriately (obviously).
Yes. You can schedule a script in cron.
In the script you can add lines to generate the file and to place the file in the location you want.
Note: Be sure that you have permissions to create a file in that specific location path.
I'm trying to add a cron job on my server, that is hosting here http://partisscan.bugs3.com/.
The provider for that is serversfree http://www.serversfree.com.
It is realy good but i can't make a cron job. I want my php file http://partisscan.bugs3.com/scan.php to be started every minute(maybe latter less often but for start). So i added a cron job in a cron job manager under control panel but it's not working.
my cron job is:
1 * * * * php -f /home/u798416153/scan.php
However it's not working:S
any ideas?
There are many possible reasons for not working.
Regarding the file:
Executing permissions of the file.
Owner of the file.
Regarding the crontab:
To which user does this crontab correspond the line you posted?
Does it have to be executed by root or any other user? If it is not root, you have to make sure that the user is not in /etc/cron.d/deny.