I have this perfectly working command:
netstat -tuplean | awk '{NR>1; if( $6 ~ /ESTABLISHED/ ) print "\033[0;31m" $5 " \033[01;31m"$6;if ($6 ~ /_WAIT/ ) print "\033[0;34m"$5 " \033[01;32m"$6}' I cannot wrap it into a watch command. Here is what I tried:
escape all single quotes (
')watch 'netstat -tuplean | awk '\''{NR>1; if( $6 ~ /ESTABLISHED/ ) print "\033[0;31m" $5 " \033[01;31m"$6 if ($6 ~ /_WAIT/ ) print "\033[0;34m"$5 " \033[01;32m"$6}'\'''output:
^[0;31m34.210.39.83:443 ^[01;31mESTABLISHED ^[0;31m34.107.221.82:80 ^[01;31mESTABLISHED ^[0;31m34.107.221.82:80 ^[01;31mESTABLISHED ^[0;34m34.117.59.81:80 ^[01;32mTIME_WAIT ^[0;34m34.117.59.81:80 ^[01;32mTIME_WAIT ^[0;31m192.168.0.1:67 ^[01;31mESTABLISHEDescape both single and double quotes (
'and")watch 'netstat -tuplean | awk '\''{NR>1; if( $6 ~ /ESTABLISHED/ ) print '\'"\033[0;31m'\'" $5 " \033[01;31m'\'"$6 if ($6 ~ /_WAIT/ ) print '\'"\033[0;34m'\'"$5 '\'" \033[01;32m'\'"$6}'\'''output:
bash: syntax error near unexpected token `print'export the command and then call it back this way:
while : do ...<cmd>...; sleep 2;done watch -n 3 -x bash -c "$cmd"it does not work neither because the same problem occurs when defining the variable.
I tried to make a script using
while : do ...<cmd>...; sleep 2;doneit does not work because it looks like the sleep delay is not taken into account; as a result, the output comes out too fast -- there is no way to read something.