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.
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
|& less
nano ~/.bashrc
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'; ) }
export -f ws
2>&1 | less;
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 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
#!/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
+1 to sudodus's script
"When you practice gratefulness, there is a sense of respect toward others." >>Dalai Lama
Originally Posted by sudodus 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.
View Tag Cloud
Ubuntu Forums Code of Conduct