I am using tail -F to monitor a severe weather alert server log file and awk to filter and execute a command if the conditions for an alert are met. I need to execute the bash command(an ssh command sent to a Pi to trigger an alert LED) in system only once, not one time for every match. Everything is working except the system command is running once for every line matched. Here is what I have so far:
tail -F /home/user/test.txt | stdbuf -oL awk '/ZZZ029/{getline; if (/SV.W/) print system("command")}'
Current output(number of lines could vary):
/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/
/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/
/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/
Expected output:
/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
I need just one line of output so the system command will run only once. Or just a way to run the command once regardless of number of lines of output.
system("command")
you want the whole pipeline to stop, or you want the pipeline to continue but for awk to never callsystem
again?system()
runssh
to interpret thecommand
notbash
. If you want to startbash
to interpret bash specific code, you'll need to constructsh
code that runsbash -c bash-specific-code-here
where that bash-specific code will have to be quoted as per sh rules.