Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crontab executes only first line

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!

like image 998
Kanstantsin K. Avatar asked Sep 18 '12 15:09

Kanstantsin K.


People also ask

Can crontab run every second?

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.

What is the use of * * * * * In cron?

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.

Does crontab run as root or user?

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.


1 Answers

It seems like cron requires an empty line an the end of crontab. I accidentally left such line and viola! both tasks executed.

like image 186
Kanstantsin K. Avatar answered Sep 19 '22 02:09

Kanstantsin K.