Tags: #bash #tmux #lsof #unix #shell #monitor #zsh
#!/usr/bin/env zsh
threshold=6000
while true; do
files=$(lsof | wc -l | xargs) # xargs for trimming white space
replace="\033[0K\r"
threshold=$threshold
msg="lsof:$files (threshold: $threshold)"
echo -ne "$msg$replace"
if [[ ! -z "${TMUX}" ]]; then
tmux rename-window -t 1 "$msg"
fi
if [ $files -ge $threshold ]; then
say "threshold $threshold exceeded"
threshold=$( expr $threshold + 1000 )
fi
sleep 1
done