"/Bin/Sh: 1: Syntax Error: Redirection Unexpected" in Crontab's Outputs

In crontab I have this job script :

0 5 * * * /home/user/job_h.bash > /home/user/log_h.log > 2&1 

where the job_h.bash contains :

#!/usr/bin/env bash
set -e
source /home/user/pyenv/test/bin/activate
python3 /home/user/pyenv/test/d_h.py
deactivate

However it outputs "/bin/sh: 1: Syntax error: redirection unexpected"

Would you please help me to understand ? I'm pretty sure that i'm using the right shebang and finally the python isn't executed 🤷‍♀️

Thank you,

3

1 Answer

I almost certain your redirection for stderr is wrong. (the last 3 characters) Try

  home/user/job_h.bash > /home/user/log_h.log 2>&1 

The problem is your command, as written is trying to redirect stdout twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest