I added the following command near the top of my shell script in order to record the script output to a file. This works with no problem when I run the script as my user, jsmith, however when the script is run as root in a crontab, I receive an error:
syntax error near unexpected token:
exec &> >(tee $LOG_PATH$TIMESTAMP.log)
I do have both $LOG_PATH and $TIMESTAMP correctly defined above the command as:
LOG_PATH="/home/jsmith/script/logs/"
TIMESTAMP="$(date -d "today" +"%Y-%m-%d-%H:%M")"
Any ideas? Thanks!
Usually, Linux feature multiple shells (sh, csh, dash, bash, etc.) which have subtle syntax differences. It is possible that you tested your script with bash, whereas crontabs are executed with dash.
I suggest you the following:
SHELL=/bin/my_shellat the beginning of your crontab (see the manpage for details).