Chiyaan Suraj
Chiyaan Suraj

Reputation: 1015

Cron job is writing the error to error log but fails to write outputs to output log file

I have 2 python codes which i schedule using cron. My codes actually runs from 10:30am to 4:20pm everyday. from 10:30am to 11:00am my codes outputs 2-3 lines every minute and after that they start outputting 30-40 lines every minute. I have scheduled my codes like this.

30 10  * * 1-5 cd /home/alpha/IBpy && python LongData.py >> /home/alpha/logs/Longdata.op 2>> /home/alpha/logs/Longdata.er
31 10  * * 1-5 cd /home/alpha/IBpy && python ShortData.py >> /home/alpha/logs/Shortdata.op 2>> /home/alpha/logs/Shortdata.er

now the problem is, My programs are working all fine they are doing everything they were supposed to do. If any error occurs they immediately write the error to error log file but they are not even writing single line to output file. I checked almost every possible posts that can help me in here and in stackoverflow but unfortunately none of them helped me. however if i start the same programs at 11:00am(when programm starts outputing 30-40 lines) instead of 10:30 everything works fine. I really don't know what wrong thing am i doing. i am not supposed to start my program at 11. Any help would be appreciated.

Upvotes: 1

Views: 101

Answers (1)

Chiyaan Suraj
Chiyaan Suraj

Reputation: 1015

Seems i got this problem since the data to stdout was buffered. According to this post i just changed my cron job to

31 10  * * 1-5 cd /home/alpha/IBpy && stdbuf -i0 -o0 -e0 python ShortData.py >> /home/alpha/logs/Shortdata.op 2>> /home/alpha/logs/Shortdata.er

and every thing is working fine now.

Upvotes: 1

Related Questions