Score:1

What is the best directory to place your cron jobs?

sh flag

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.

in flag
Does this answer your question? [Why is my crontab not working, and how can I troubleshoot it?](https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it)
Titi avatar
sh flag
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
cn flag
@Titi Did you read the suggested answer? Particularly how cron.d has an additional column for the username compared to the traditional user crontab
Titi avatar
sh flag
@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
diya avatar
la flag
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
Score:2
ro flag

/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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.