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
my_python_file.py
script. Can you capture the raw output from that script (incron
) 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