Crontab fails to execute docker exec background task in ubuntu
Several background tasks were added to the crontab task. After a few days of execution, it was found that several business tasks were not executed. After checking, the first few background tasks were normal, but the background tasks performed using docker exec had no results.
0 2 * * * docker exec -it sphinx /bin/bash -c '/bin/indexer -c /usr/local/etc/csft.conf base_04007cn --rotate' >> /opt/logs/sphinx.log;
Open the crontab log in the crontab configuration, and then you can view the crontab log in the corresponding file /var/log/cron.log.
However, in the log, only the record that the docker exec background task was not executed, and the MAIL record sent by error: CRON: (root) MAIL (mailed 30 bytes of output but got status 0x00ff from MTA#012). There are no other error messages. Later, when I carefully checked the docker command, I suddenly realized that adding the -it parameter to the docker exec command means opening a terminal, and if the terminal cannot be operated in the background task, it must not be executed.
The solution is to remove -it in the task command.