« Back to Index

Shell: Track list of open files

View original Gist on GitHub

Tags: #bash #tmux #lsof #unix #shell #monitor #zsh

Track list of open files.sh

#!/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