Running a cron job manually and immediately

Here’s what I did, and it seems to work in this situation. At least, it shows me an error, whereas running from the command line as the user doesn’t show the error.


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 could obviously be expanded to make use of sudo or such for more flexibility.

Hope this helps others.

Leave a Comment