I am trying to run a shell script using the crontab scheduler, and I am redirecting the log of the script output to some temp log file using the following command.
sh somescript.sh 1> /location/somefile.log
Evrytime the cronjob triggers this script, It creates a zero byte file in the location specified. I also tried with
sh somescript.sh > /location/somefile.log
But no luck. If I run a simple command like
rm -rf <somefile>
then this command is running sucessfully by cron. But why is it not creating the log of the script that has been run? Any help will be higly appreciated.
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Thank You.
The UNIX and Linux Forums
---------- Post updated at 13:56 ---------- Previous update was at 13:55 ----------
Unless your script resides in /root, cron won't find it. Put it into the crontab using the absolute path and see if it works.
1) In most unixes the errors will be in root mail .
2) As suggested above, refer to the script name by absolute path unless the script happens to be in the limited default path available in cron.
3) There may also be need to set PATH in the script or refer to commands by absolute path,
4) You don't need the "sh " in front of the command. cron defaults to "sh".
5) If you want to capture all output from the script you will need to redirect the error channel too.
Suggested outline for the command field in the crontab line: