how can I make cron run a job right now, for testing/debugging? without changing the schedule!
You can force the crontab to run with following command:
run-parts /etc/cron.daily
You can simulate the cron user environment as explained in "Running a cron job manually and immediately". This will allow you to test the job works when it would be run as the cron user.
Excerpt from link:
Step 1: I put this line temporarily in the user's crontab:
* * * * * /usr/bin/env > /home/username/tmp/cron-env
then took it out once the file was written.
Step 2: Made myself a little run-as-cron bash script containing:
#!/bin/bash
/usr/bin/env -i $(cat /home/username/tmp/cron-env) "$@"
So then, as the user in question, I was able to
run-as-cron /the/problematic/script --with arguments --and parameters
As far as I know there is no way to directly do that as cron has a special purpose - running schedules commands at a specific time. So the best thing is to either to manually create a (temporary) crontab entry or write a script which removes and resets the environment.
Explanation of "removes and resets the environment":
A wrapper script could be started with env -i
(which removes the environment), which would source a saved environment (making sure to export all variables, possibly by setting set -a
first) before starting your script.
The saved environment would be the default environment of a cron job, recorded by running env
(or declare -p
depending on what shell your cron jobs use) as a cronjob, saving its output.