( tail -f -n0 /proc/loadavg 2> /dev/null & ) | grep -q "^[1-9]"
echo 'The millenium crystals are gunna blow!'

I though I was being clever and that would work. It just hangs and never reacts unless from run start and the first char is [1-9]

  • Just to nitpick: The load averages aren't percentages. – Kusalananda Mar 7 at 9:54

tail does look for new lines, not for line chages:

-f, --follow[={name|descriptor}]
      output appended data as the file grows;

If you want to verify this behaviour for yourself, you can use this command to change a line in testfile:

while true ; do
    sed "s/^.*$/$(date)/" -i testfile
    sleep 1

You could use a wile loop to check for line changes:

while true ; do
    grep -q "^[1-9]" /proc/loadavg && echo "$message"
    sleep 1

I think you can in conjunction use tail with grep for changes and not just new lines.

I just read before I came here that /proc/loadavg isn't actually a file but a kernel interface and maybe you are right, but even if it could I will still be up the swanny.

I was hoping for an inotify notification rather than the load of just constant loops but seems like computer says no.

  • I take it that something like Nagios is not on the table for this? – Raman Sailopal Mar 7 at 10:58
  • :) maybe not as nagios is likely doing the same and polling rather than using a tail inotify Just means I can not use tail in a notification event scheme and will just have to use polling like ctx suggests – Stuart Naylor Mar 8 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.