Use a systemd-service + systemd-timer. You can then run "systemctl start myjob.service" to check that it runs as you expect. If it works "systemctl enable --now myjob.timer" to kick it off as scheduled
Self Hosted - Self-hosting your services.
A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.
Rules
- No harassment
- crossposts from c/Open Source & c/docker & related may be allowed, depending on context
- Video Promoting is allowed if is within the topic.
- No spamming.
- Stay friendly.
- Follow the lemmy.ml instance rules.
- Tag your post. (Read under)
Important
Beginning of January 1st 2024 this rule WILL be enforced. Posts that are not tagged will be warned and if not fixed within 24h then removed!
- Lemmy doesn't have tags yet, so mark it with [Question], [Help], [Project], [Other], [Promoting] or other you may think is appropriate.
Cross-posting
- !everything_git@lemmy.ml is allowed!
- !docker@lemmy.ml is allowed!
- !portainer@lemmy.ml is allowed!
- !fediverse@lemmy.ml is allowed if topic has to do with selfhosting.
- !selfhosted@lemmy.ml is allowed!
If you see a rule-breaker please DM the mods!
You can use crontab -e
from user. That set user environment to usual state. Or you can use systems timers instead crontab.
Or you can set all environment variables inside cron file.
Depending on what your setup is like, you could use something other than cron.
Kubernetes and Nomad both have cron-like schedulers. It's convenient to keep your cronjob definitions near the app code.
I've also been using windmill.dev lately for some simple cronjob-like tasks and it's working pretty great. It also has a UI if that helps.
I basically combine a few mechanisms to mitigate that:
- Having cron call scripts deployed to a fixed location I can manually test or use on demand as needed
- Piping each script's output/exit code to healtchecks.io so I can get feedback notifications when/if they fail
- Using Ansible to deploy everything so it's all repeatable and version controlled
Put all the logic in a php file and just configure crontab to run the file at the given interval and output the results to a log file. Use crontab.guru to help with scheduling.
Always use absolute path. If you write some shell snippet which may be run in different environment, avoid use just command name for uncommon one.
If Cron is too hard for you (it is really easy so I don't really understand your problems) then check out runat instead. Simple and easy to use with all the features I would suspect you use in cron
Wrap all the cron job tasks in a bash script and make sure it works. Call the script directly in the cron configuration. Dump the output of the cronjob to a logfile. Set it up to run every minute so you can ensure it works via the cron environment.