Search code examples
bashtee

Using tee with logger : syntax error near unexpected token `('


Scenario 1 : Command line

    ./myscript.sh 2>&1 | tee >(logger -t 'MYSCRIPT')

Works fine and perfect : displays errors and output msg on command line as well as puts in the lo

Scenario 2 : Adding it to a crontab

    20 19 * * * imuser /home/imuser/myscript.sh 2>&1 | tee >(logger -t 'MYSCRIPT')

Error : syntax error near unexpected token `('

What is that I am missing here ?


Solution

  • cron calls /bin/sh, which has a limited syntax compared to bash.

    Try

    20 19 * * * imuser /home/imuser/myscript.sh 2>&1 | bash -c 'tee >(logger -t MYSCRIPT)'