I'm trying to setup several cron jobs on VPS under centos/whm. I've added to /var/spool/cron/root following lines:
*/5 * * * * find /some-dir/* \( ! -iname ".ht*" \) -delete
*/10 * * * * find /some-other-dir/* \( ! -iname ".ht*" \) -delete
but only the first line executed ( for /some-dir/). If I swap lines - /some-other-dir/ executed, /some-dir/ - not. I've tried to put semicolons at the end of each line, to put spaces, tabs, change file encoding - nothing.
How can I make cron process both tasks?
here is the /var/log/cron output:
Sep 18 11:05:01 host crond[3302]: (root) CMD (find /some-dir/* \( ! -iname ".ht*" \) -delete)
Sep 18 11:10:01 host crond[3303]: (root) RELOAD (/var/spool/cron/root)
thanks!
By default, cron checks crontabs for cronjobs every minute. If you want to run a job every n seconds you need to use a simple workaround.
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week . 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.
Like any other user, root has a user crontab. Essentially the same as any other user crontab, you are editing the root crontab when you run sudo crontab -e . Jobs scheduled in the root user crontab will be executed as root with all of its privileges.
It seems like cron requires an empty line an the end of crontab. I accidentally left such line and viola! both tasks executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With