Append/Write CRON Output to Log File in Linux (Unix)

Append or Write CRON Output to Log File

Append/Write CRON Output to Log File in Linux (Unix)

Append CRON Output to Log :

           The following syntax can be used to append the output of the shell scripts to the given file.

Syntax :

CRON_EXPRESSION COMMAND >> /OUTPUT_LOG_FILE_PATH/LOF_FILE 2>&1

Example :

           The following example will append the output of the shell script test.sh to cron_output.log in the path /usr/local.

45 * * * * sh /usr/local/test.sh >> /usr/local/cron_output.log 2>&1

Overwrite CRON Output to Log :

           The following syntax can be used to write the output of the shell scripts to the given file. If the output file already exist while writing, the old content will be replaced by new content.

Syntax :

CRON_EXPRESSION COMMAND > /OUTPUT_LOG_FILE_PATH/LOF_FILE

 Example :

The following example will write the output of the shell script test.sh to cron_output.log in the path /usr/local.

45 * * * * sh /usr/local/test.sh > /usr/local/cron_output.log

[ YOU MAY ALSO LIKE ]

Leave a Reply