You might consider having your script take care of its own logging. While this is certainly possible, (although a little complex and not very readable), we feel strongly that it is the responsibility of the caller to take care of logging. If you find a script that takes care of its own logging, you might encounter some of the following issues:
- Multiple users run the same script at different intervals, to a single log file
- The log file needs to have robust user permissions to ensure correct exposure
- Both ad hoc and scheduled runs will appear in the log file
Simply put, delegating the responsibility of logging to the script itself is asking for trouble. For an ad hoc command, you get the output right in your Terminal. If you need it for any other purpose, you can always copy and paste it somewhere, or redirect it. Even more probable is running the script with a pipe to tee, so output is shown to your Terminal and saved to a file at the same time. For scheduled runs from cron, you need to think once about redirection: when you create the schedule. In this case, especially if you use the Bash 4.x construct of &>>, you will always see all output (stdout and stderr) appended to the file you specify. In this, there is almost no risk of missing any output. Remember: tee and redirections are your friends, and when used properly they make a great addition to any script scheduling!