Results 1 to 4 of 4

Thread: Watch progress of sync operations and quit it with q

  1. #1
    Join Date
    Oct 2019
    Beans
    33

    Question Watch progress of sync operations and quit it with q

    I like to combine these 2 commands in order to watch progress of sync command and then quit it with 'q'.

    Code:
    watch-n1 'grep -E "(Dirty|Write)" /proc/meminfo; echo; ls /sys/block/ | while read device; do awk "{ print \"$device: \"  \$9 }" "/sys/block/$device/stat"; done';

    Source:
    https://unix.stackexchange.com/a/713647/366010

    and quit it qith q by either:

    Code:
    2>&1|less
    or
    Code:
    |& less


    Source: https://askubuntu.com/a/1415867/928088

    So I've created a fucntion:

    Code:
    nano ~/.bashrc

    and added:


    Code:
    function ws() {
        ( watch -n1 'grep -E "(Dirty|Write)" /proc/meminfo; echo; ls /sys/block/ | while read device; do awk "{ print \"$device: \"\$9 }" "/sys/block/$device/stat"; done'; )
    }
    Code:
    export -f ws
    So, with 'ws' I get:



    Now if I add:

    Code:
    2>&1 | less;

    to combine both and make it:


    Code:
    function ws() {
        ( watch -n1 'grep -E "(Dirty|Write)" /proc/meminfo; echo; ls /sys/block/ | while read device; do awk "{ print \"$device: \"\$9 }" "/sys/block/$device/stat"; done'; ) 2>&1 | less;
    }
    I get this jumbled output:



    So how to combine these 2 commands? Many thanks in advance.
    Attached Images Attached Images

  2. #2
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Watch progress of sync operations and quit it with q

    I suggest that you make a bash shellscript and use the bash version of read that is activated by a 'q' in order to kill watch.

    Code:
    #!/bin/bash
    
    watch -n1 'grep -E "(Dirty|Write)" /proc/meminfo;
    echo;
    ls /sys/block/ | while read device;
    do
     awk "{ print \"$device: \"  \$9 }" "/sys/block/$device/stat"
    done' & pid=$!
    
    while true
    do
     read -sn1 -t2 ans
     if [ "$ans"  == "q" ]
     then
      kill -9 "$pid"
      echo "
    quit"
      exit 0
     fi
    done

  3. #3
    Join Date
    May 2018
    Location
    Here and There
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: Watch progress of sync operations and quit it with q

    +1 to sudodus's script
    "When you practice gratefulness, there is a sense of respect toward others." >>Dalai Lama

  4. #4
    Join Date
    Oct 2019
    Beans
    33

    Thumbs up Re: Watch progress of sync operations and quit it with q

    Quote Originally Posted by sudodus View Post
    I suggest that you make a bash shellscript and use the bash version of read that is activated by a 'q' in order to kill watch.
    It's working perfectly. Many thanks.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •