2

We have a machine that executes cron jobs. We'd like to upload (via scp) cron job files to. Here is an example of a cron job file (test.cron):

* * * * * echo "test" > /tmp/test_cron

This runs if you do it using crontab -e then save, and then that ends up in /var/spool/cron/crontabs/$USER, we can't use this anymore (company policy).

If I place this file test.cron in the /etc/cron.d it doesn't run. Do I need to change this file syntax or put this file elsewhere so it's picked up by cron deamon and ran?

Update:

When I paste contents of the test.cron into crontab -e it gets executed. My crontab syntax seems to be valid.

My question is: Where do I need to put/drop/place test.cron file with the content above, so that it gets picked up by cron daemon?

More context: I don't know in advance at what interval the cron file command will need to be ran. None of these are probably a good place "cron.daily/ cron.hourly/ cron.monthly/ cron.weekly/" I could be wrong that's why I'm asking this question.

Titi
  • 23

1 Answers1

3

/etc/cron.d is a feature of the crond that may have to be explicitly enabled. It is enabled by default on Debian-based distros. So /etc/cron.d is the right place when you are on a Debian derivative.

The cron manpage on Debian says:

Files in [/etc/crond.d] must conform to the same naming convention as used by run-parts(8) : they must consist solely of upper- and lower-case letters, digits, underscores, and hyphens. This means that they cannot contain any dots.

So you have to rename your test.cron to eg. test_cron and it should start to work.

Christo
  • 81
  • 2