Sample Header Ad - 728x90

awk - combine 2 steps into one

1 vote
2 answers
106 views
I need to read the output table of transmission-remote to determine if a download is taking place. This is currently achieved with trans="transmission-remote 0.0.0.0:9092 -n $user:$pass -l" [ "$($trans | awk '! /awk/ && /n[/]a/ {print $2}')" == "n/a" ] \ || [[ $($trans | awk '! /awk/ && /%/ {print substr($2, 1, length($2)-1)}' | sort -n | head -n 1) -lt 100 ]] It's looking for either the presence of string 'n/a' or a completion of <100%. The way it's written it must probe 'transmission-remote' twice for the same table. Sample table output: ID Done Have ETA Up Down Ratio Status Name 1 100% 3.38 GB Done 0.0 0.0 1.00 Finished Fish Documentary.mkv 2 100% 5.87 GB Unknown 0.0 0.0 0.00 Idle Ethical Coding.pdf 3 100% 1.33 GB Done 0.0 0.0 1.99 Finished Bacon.jpg 4 100% 1.26 GB Unknown 0.0 0.0 0.00 Idle Eggs.png 5 100% 10.89 GB Done 0.0 0.0 1.00 Finished Invest in gold.pdf Sum: 23.63 GB 0.0 0.0 Is it possible to combine the awk arguments into one, or perhaps someone could suggest an easier or cleaner way to achieve the desired outcome? The ultimate goal is to have the red LED on the NAS flash red when a download is taking place, and turn solid white when all downloads have completed. The original script is here: https://pastebin.com/tKXc8mFW
Asked by Tony Puryer (31 rep)
Apr 5, 2024, 03:55 AM
Last activity: Apr 5, 2024, 01:17 PM