How to redirect stderr to a file in a cron job

前端 未结 1 2057
忘了有多久
忘了有多久 2020-12-31 00:55

I\'ve got a cron job that is set up like this in my crontab:

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

It

相关标签:
1条回答
  • 2020-12-31 01:12

    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

    0 讨论(0)
提交回复
热议问题