How can I prevent my terminal from breaking?

11/15/2019

I am using a watch command(in a shell script) in my docker image.

Command:

watch -d -t -g ls -la  ${DIR_TO_WATCH} && sleep 5  && ${COMMAND} | tee

This command is watching a directory and if there is any change in the directory structure, we perform certain actions.

I am using this docker image in my helm chart. Now, when I deploy the chart and check the logs of that pod, my terminal breaks and it will not be user friendly anymore.

Command:

kubectl logs -f pod-name -n name-space

After this, we need to reset terminal settings to get the terminal behave normal.

Is there anything that can be done to prevent this?

Best Regards, Akshat

-- Akshat Sharma
docker
kubernetes
shell
watch

1 Answer

12/4/2019

Solved this by sending output of watch to /dev/null.

watch -d -t -g ls -la ${DIR_TO_WATCH} > /dev/null && sleep 5 && ${COMMAND} | tee

The reason, according to my understanding, behind broken terminal was:

Two different command's logs(logs from watch and ${COMMAND}) were showing up on the same terminal at the same time, which resulted in creating a new terminal over the default one(which I am not sure how), causing the default terminal to break.

While ${COMMAND} logs were crucial for me, I did not need to view or monitor logs from watch. Hence, I sent the log outputs of watch to /dev/null and it solved my problem.

Please correct me if my understanding or approach is wrong.

Thank you.

-- Akshat Sharma
Source: StackOverflow