LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Direct Cron Output in Text (https://www.linuxquestions.org/questions/linux-server-73/direct-cron-output-in-text-804963/)

carlosinfl 04-29-2010 08:08 AM

Direct Cron Output in Text
 
My server has no MTA (Postfix, Sendmail, Exim) installed so it can't email me the results of any cron job I schedule. I would then like to have the results from Cron be dumped into a small text file so I can read it later to view any issues.

Right now my job is as follows:

Code:

01 18 * * * /usr/bin/shellscript.sh
Above you see my script I want to run every day @ 6:01 pm. My question is what would the cron line look like if I wanted the results dumped into a random text file somewhere on my system?

colucix 04-29-2010 08:20 AM

You can redirect both the standard error and the standard output to a file with the current date in its name, e.g. something like this:
Code:

1 18 * * * /usr/bin/shellscript.sh > /path/to/$(date +\%Y\%m\%d)_cron.log 2>&1
Alternatively, you can put the following line of code at the beginning of the script itself:
Code:

exec > /path/to/$(date +%Y%m%d)_cron.log 2>&1
that has exactly the same purpose.


All times are GMT -5. The time now is 04:16 PM.