A common way to log crontab errors looks like below:
1 */8 * * * sh /pseudo_path/test.sh 2>> my_err_log 
It's a concise command, but it can't record the error occurred time, and the path of script file is omitted.
So I wrote an error record function:
PROGNAME=$(readlink -f "$0")
SCRIPT_ERR_LOG_PATH="/pseudo_path/script_err_log"
error_exit()
{
    timestamp="$(date +%Y%m%d-%H:%M:%S)"
    x_info=$(echo "Error_${PROGNAME}:Line_${1:-"null"}_")
    zeta=$x_info$timestamp
    echo "$zeta" >> $SCRIPT_ERR_LOG_PATH
    exit 1
}
This function can log the time the error occurred, together with the absolute path of the script. But the downside is that I have to add || error_exit $LINENO at every line of my script to make it work. With Vim's bulk substitution it could be much easier, but it still looks like a clumsy solution.
So, is there a smarter or more efficient way to do the same task?


sh /pseudo_path/test.shthat receives stderr and stdout separately and adds timestamps to the lines from stderr and writes them to file, but passes on stdout transparently. Python'ssubprocess.Popen()combined with.communicate()e.g. works well.