7 Comments

  1. Dave

    The 'watch pipe with awk' command is wrong; awk does not do anything here. That is because the argument to watch is enclosed in double quotes, which evaluates the '$2' part _before_ even passing it to watch. So awk just receives "print" as command (also seen in the screenshot) and subsequently just prints what it gets.

    You need to escape the $ to get awk to do what it should:

    watch -n1 "sensors | grep temp | awk '{ print \$2 }'"

    Reply

    • By golly, you're right! You're the first one in 4 1/2 years to notice.

      Reply
  2. kobo

    Thank you for your blog. It is very useful for me.

    Reply
  3. CM

    This may help someone new to shell scripting if you find yourself on a system without watch:

    ## while true; do ; sleep ; done

    will work as a minimal implementation, work with pipes, etc. As an example like the post above:

    ## while true; do clear; sensors | grep temp | awk '{ print $2 }'; sleep 1; done

    Any number of commands can be stacked with semi-colons separating them.

    Reply

  4. You coule also use tail -F file...
    Auto refresh and display even when the file change.

    Reply

    • You are exactly correct. I was struggling to come up with a good example when I wrote this, so I used the tail example. tail -F is certainly more appropriate for that particular task.

      Thanks for your comment.

      Reply

  5. Completely agree. `watch` proved to be one great tool that I personally find it extremely helpful. It is also cool when you add the '-d' argument, it highlight the differences between successive updates so you can actually easily notice when something has changed.

    for example:

    ## watch -d -n1 "sensors | grep temp | awk '{ print $2 }'"

    cheers

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.