2

I have a shell script that works fine when run manually, but fails when run through the crontab. The script essentially does as follows:

Python script to get audio data and pipe to stdout | ffmpeg the data from stdin and pipe to stdout | stream the data from stdin

When run through crontab the streaming fails, complaining that there is no data at stdin (...No (more) data available on standard input).

I found this answer which seems to allude to the issue of file descriptors in crontab, but I would appreciate some more details on the problem and the best way to get around it.

EDIT: Troubleshooting the issue by trying each individual command separately shows that the issue starts in the python script which complains:

close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr"

instead of outputting audio data. Following the advice here and here (added sys.stdout.flush() to the end of the file) I can see the actual error message is:

Traceback (most recent call last):
  File "/home/*username*/testing.py", line 109, in <module>
    sys.stdout.flush()
IOError: [Errno 9] Bad file descriptor

So perhaps it's more of a python issue..though from the error it stil seems to have to do with stdin/stdout

  • 3
    Please show us the exact command/script and the exact error message. Please do not respond in comments; edit your question to make it clearer and more complete. – G-Man Says 'Reinstate Monica' Jun 7 '17 at 17:10
  • @G-Man Done, though not sure how much information it adds in this specific instance, which is why I left it general. – andrewmh20 Jun 7 '17 at 17:18
  • It points a finger at the my_python_file.py script. Can you capture the raw output from that script (in cron) and write it to a file? Something like /usr/bin/python /home/tzvi/my_python_file.py >/tmp/my_file.dat 2>/tmp/my_file.err – roaima Jun 7 '17 at 17:20
  • @roaima Done. Thank you, I'm sorry I didn't think to consider that the problem could have started somewhere else--though it does still seem to me to be related to piping in cron – andrewmh20 Jun 7 '17 at 17:32
  • 1
    Fixed. I will try to update with an answer later – andrewmh20 Jun 7 '17 at 18:47
2

As it turns out, the issue really was the python file and cron, but not an issue with file descriptors (stdin/stdout) in the way I had expected.

Rather, as per this answer having a line asking for user input while running through cron was causing the issue. I solved the issue by removing the request for user input as for me it was unnecessary.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.