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: https://github.com/poleguy/run-as-cron.git
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:
https://stackoverflow.com/questions/4984725/test-a-weekly-cron-job
https://serverfault.com/questions/85893/running-a-cron-job-manually-and-immediately
cron
runs it, it could be affected by ENV or shell specific stuff (~
expansion) or ownership and permission stuff or ... – Ali Jul 10 '12 at 10:48