1

I'd like to monitor apps that have inotify instance in real-time with watch using something similar to:

watch "for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | sort -nr"

I was hoping the output would appear similar to

for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | sort -nr

but instead this fails with a message about readlink having a missing an operand. I've been using using quotes to wrap my complex shell commands to view in watch for a while now and I guess I was surprised this one didn't work. I guess watch is designed for something different, just running a command and updating the output it sees. But I can't seem to bring this command up in sh or bash with:

watch "/bin/bash for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | sort -nr"
watch bash "for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | sort -nr"
watch sh "for foo in /proc/*/fd/*\; do readlink -f $foo\; done | grep inotify | sort | uniq -c | sort -nr"
watch bash "for foo in /proc/*/fd/*\; do readlink -f $foo\; done | grep inotify | sort | uniq -c | sort -nr"

but this gives sh: 1: Syntax error: "do" unexpected, and/or various syntax errors. After trying this one last thing (escaping the ; with \;) but I get /bin/bash: for: No such file or directory. but am curious to know why this works and if I can avoid using a script file, eg: watch which-programs-created-inotify-instances.sh

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
Tomachi
  • 111

0 Answers0