3

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.

2 Answers2

2

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.

1

Your syntax is supposed to work in (ba)sh. Check the documentation of the default shell on your system for proper syntax. Note that different shells have different support for redirections. For example, in csh you can't redirect stderr to stdout.

If this is not the case, I will say it is a bug in the python script itself. If you are checking time/date inside your python scripts make sure that you get the correct time format.

Bichoy
  • 3,106
  • 2
  • 21
  • 34