How can I make cron run a job right now, for testing/debugging? without changing the schedule!?

preview_player
Показать описание
Unix & Linux: How can I make cron run a job right now, for testing/debugging? without changing the schedule!?

The Question: I have a cron job that is scheduled to run everyday, other than changing the
schedule, is there any other way to do a test run of the command right now to
see if it works as intended?
EDIT: (from the comments) I know the command works fine when enter it in shell
(my shell), but I want to know if it works correctly when cron runs it, it
could be affected by ENV or shell specific stuff (~ expansion) or ownership and
permission stuff or ...

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 33 people ==
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 crontab entry or write a script which removes
and resets the environment.

== This solution helped 55 people ==
You can simulate the cron user environment as explained in https://
85906. 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

== This solution helped 77 people ==
You can force the crontab to run with following command:

Рекомендации по теме