Where to place a script for cron jobs

Hi,
I’m trying to set up a cron job. I have a script which I want to run daily by a cron job. Where would be the best place to place it, so it is executable by the cron job?

Thanks for your help.

I guess you want to add a new Route that you can call with your cronjob, there you can run your script.

The best place is outside of the web root, apart from that it doesn’t matter as long as you pass the correct path to the script. But it depends on what that script is supposed to do.

Thanks for your help. The script is for updating some values on pages. It checks if an entry is older than X days and marks it as closed. And sends an email if there is an unclosed entry.
I added a route and that works great if I call it in my browser. But I’m not sure how to run it with my cron job. If I add curl http://www.mysite.ch/path/to/route nothing happens. Maybe it is more a cron problem…
But then I also tried to write my script in update.php.

Unfortunately I have only access to the web root folder. If I place it in the root, is that a security risk? And do I have to include the bootstrap.php to call:

$site = kirby()->site();

In that case I would put the code in a plugin or template where you have access to all Kirby methods. If you use a route, make sure it can’t be accessed by anyone else.

I have a cronjob calling a route defined in a plugin. In the route I perform some content update. Everything works great but how can I prevent this route to be accesed direclty from anyone else than the cronjob?

The safest way would probably be to put the script outside the doc root and/or set the file permissions so that the file can only be accessed by the cron job.

Other suggestions can be found here: security - Run a php script only from Cron or check if request from cron? - Stack Overflow

If you need access to Kirby in your script, you can require the bootstrap.php file in your script, like in this user migrate script: How to migrate users | Kirby CMS