C
C
celovec2020-12-11 11:19:15
linux
celovec, 2020-12-11 11:19:15

Tail: inotify cannot be used, reverting to polling: Too many open files?

I'm doing this simple chat. We launch it through the console.

#!/bin/bash
echo "Please enter your name:"; read USER
echo "[$(date)] ${USER} joined the chat" >> ./chat.log
echo "[$(date)] Welcome to the chat ${USER}!"
tail -n 0 -f ./chat.log --pid=$$ | grep --line-buffered -v "] ${USER}>" &
while read MSG; do echo "[$(date)] ${USER}> ${MSG}" >> ./chat.log; done


If I run this script more than 150 times, I get an error:
tail: inotify cannot be used, reverting to polling: Too many open files
Please help me somehow optimize it to get rid of this error.
I know that you can increase the ulimit, but I just want to somehow optimize the script. Is it possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xibir, 2020-12-11
@xibir

Run as root

echo 'fs.inotify.max_user_instances = 1048576
fs.inotify.max_user_watches = 1048576' >> /etc/sysctl.conf && sysctl -p

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question