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

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

    I don't understand your question? Why not simply run the command?

    I know the command works when enter it in shell (my shell), but I want to know if it works when `cron` runs it, it could be affected by ENV or shell specific stuff (`~` expansion) or ownership and permission stuff or ...

    So why not create new cron job run every minute with same command?

    This is exactly what I ended up doing, but I wondered if there is a way to tell cron you want a test run on job no 7 ! Surely others have had this problem/request/wish before!

    Very late to the scene here through google but there was everything wrong about favadi's reply. It was clear he wanted to test it from cron and without editing the crontab specifically to do that. LIttle worse than someone telling you what you want is wrong when they have'nt tried to understand the use case.

    @Ali your question is 100% valid (too bad people were originally so skeptical). Meanwhile, however, please consider changing the accepted answer.

    Thanks @pestophagous yeah, I think there are quite a few good and helpful answers here, still seems like the correct answer to the question is the one accepted. Strictly speaking you cannot make cron itself run the command, you need to run things using some other tool, which kinda defeats the purpose. which one would you say is the correct answer?

    @Ali when you put it that way, I understand your rationale (that strictly speaking there is no cron-native way to make cron itself run the task at an improvised time). The answer from Vadim-Sluzky can be useful in many cases, but for those truly-hard-to-pin-down issues, Michael-Barton's answer is more appropriate. I guess if you just "un-select" the current correct one and leave it with no "officially" correct one, then votes alone will allow other things to rise to the top.

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

    Why is this accepted answer? And why does it have 31 upvotes? As I see it, it would be best to simply delete this answer entirely.

    @RolandPihlakas which other answer would you pick instead?

    March 2020 : Please unaccept this answer as it is simply false and misleading.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM