How to redirect stderr to a file in a cron job

It’s the other way around:

*/1 * * * *  sudo /home/pi/coup/sensor.py  >> /home/pi/sensorLog.txt 2>&1

2>&1 will redirect standard error (2) to standard output (1) which -in turn – was redirected to your log file. So, at the end, both stderr and stdout will go to your sensorLog.txt

Leave a Comment