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.

5
  • 1
    Does this answer your question? Why is my crontab not working, and how can I troubleshoot it? Commented Dec 13, 2022 at 13:31
  • hey @GeraldSchneider my crontab is working, but I am asking where should I drop the file in (which directory so that it gets picked up by cron). I ll edit question to provide more clarity
    – Titi
    Commented Dec 13, 2022 at 13:33
  • 2
    @Titi Did you read the suggested answer? Particularly how cron.d has an additional column for the username compared to the traditional user crontab Commented Dec 13, 2022 at 13:39
  • @HåkanLindqvist yes I did, I tried that and it worked. Is there any other way other than placing files in /etc/cron.d ? thanks
    – Titi
    Commented Dec 13, 2022 at 13:42
  • Regarding your statement: "/var/spool/cron/crontabs/$USER, we can't use this anymore (company policy)." What is your actual policy? What needs to be achieved there? Because opening up root SFTP access (needed to drop files into /etc/cron.d ) is hardly an improvement compared to allowing a regular user to manage their own cronjobs IMHO
    – diya
    Commented Dec 13, 2022 at 15:44

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .