Daladim's answer was useful to me. It runs the command immediately, not after up to 59 seconds later as the "* * * * *
" style answers do. It presents the output as soon as the command runs.
I have extended it a bit, adding the ability to run as any user, not just root, fixing some corner case bugs, and adding a specific message with instructions to bootstrap the environment to match cron.
I put it up on GitHub.
Link a command called run-as-cron to this file from your path.
If you have a crontab entry like this:
0 0 * * * command.sh --option
test it like this:
run-as-cron command.sh --option
or as root:
sudo run-as-cron command.sh --option
or as some other user:
sudo su otheruser
run-as-cron command.sh --option
Note, that the very first time you run this as a user you'll need to add a command to crontab -e
and wait a minute to grab the environment.
These questions and answers might also be useful: