1

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!

1 Answer 1

1

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:

  1. check what shell your script requires (looks at the first line)
  2. tell cron to use that shell, i.e., set SHELL=/bin/my_shell at the beginning of your crontab (see the manpage for details).
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I will try this out. My script requires bash (#!/bin/bash)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.