Run bash command from awk system only once2019 Community Moderator ElectionMake awk use bash with the system() commandrecursive search for a pattern, then for each match print out the specific SEQUENCE: line number, file name, and no file contentsRun unix command on awk fieldWhat is wrong with my init.d script [Segmentation fault]Merging 2 files records by templateOverwrite file using AWK in a for loopTail Grep - Print surrounding lines until pattern is matchedBash Script to take a file as input and run awk command on another fileHow to run bash commands from within awk?Have `xargs` run the arguments it's received every <maximum amount of time> instead of every `-n` arguments?

Proving a function is onto where f(x)=|x|.

If a character with the Alert feat rolls a crit fail on their Perception check, are they surprised?

How do ground effect vehicles perform turns?

Is camera lens focus an exact point or a range?

Journal losing indexing services

What (else) happened July 1st 1858 in London?

Can a significant change in incentives void an employment contract?

Could the E-bike drivetrain wear down till needing replacement after 400 km?

Database accidentally deleted with a bash script

Translation of Scottish 16th century church stained glass

Transformation of random variables and joint distributions

Could solar power be utilized and substitute coal in the 19th Century

How do I repair my stair bannister?

Some numbers are more equivalent than others

How do I implement a file system driver driver in Linux?

Did US corporations pay demonstrators in the German demonstrations against article 13?

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

Can someone explain how this makes sense electrically?

Can not upgrade Kali,not enough space in /var/cache/apt/archives

Is XSS in canonical link possible?

Indicating multiple different modes of speech (fantasy language or telepathy)

List of people who lose a child in תנ"ך

Reply 'no position' while the job posting is still there

Is it possible to have a strip of cold climate in the middle of a planet?



Run bash command from awk system only once



2019 Community Moderator ElectionMake awk use bash with the system() commandrecursive search for a pattern, then for each match print out the specific SEQUENCE: line number, file name, and no file contentsRun unix command on awk fieldWhat is wrong with my init.d script [Segmentation fault]Merging 2 files records by templateOverwrite file using AWK in a for loopTail Grep - Print surrounding lines until pattern is matchedBash Script to take a file as input and run awk command on another fileHow to run bash commands from within awk?Have `xargs` run the arguments it's received every <maximum amount of time> instead of every `-n` arguments?










0















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.










share|improve this question









New contributor




Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    after you calll system("command") you want the whole pipeline to stop, or you want the pipeline to continue but for awk to never call system again?

    – Jeff Schaller
    yesterday











  • Note that system() runs sh to interpret the command not bash. If you want to start bash to interpret bash specific code, you'll need to construct sh code that runs bash -c bash-specific-code-here where that bash-specific code will have to be quoted as per sh rules.

    – Stéphane Chazelas
    yesterday











  • @JeffSchaller I want the tail -F to continue watching the file but to run the system() command only once for each time matches are found, regardless of how many matches there are.

    – Jake
    9 hours ago












  • I'm having trouble putting together these two phrases: "run the system() command once" -- and -- "each time matches are found, regardless of how many matches there are". Do you want the command run for the first match, and that first match only?

    – Jeff Schaller
    9 hours ago











  • Yes, for the first match only.

    – Jake
    9 hours ago















0















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.










share|improve this question









New contributor




Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    after you calll system("command") you want the whole pipeline to stop, or you want the pipeline to continue but for awk to never call system again?

    – Jeff Schaller
    yesterday











  • Note that system() runs sh to interpret the command not bash. If you want to start bash to interpret bash specific code, you'll need to construct sh code that runs bash -c bash-specific-code-here where that bash-specific code will have to be quoted as per sh rules.

    – Stéphane Chazelas
    yesterday











  • @JeffSchaller I want the tail -F to continue watching the file but to run the system() command only once for each time matches are found, regardless of how many matches there are.

    – Jake
    9 hours ago












  • I'm having trouble putting together these two phrases: "run the system() command once" -- and -- "each time matches are found, regardless of how many matches there are". Do you want the command run for the first match, and that first match only?

    – Jeff Schaller
    9 hours ago











  • Yes, for the first match only.

    – Jake
    9 hours ago













0












0








0








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.










share|improve this question









New contributor




Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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.







shell-script awk






share|improve this question









New contributor




Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 7 hours ago







Jake













New contributor




Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









JakeJake

11




11




New contributor




Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 2





    after you calll system("command") you want the whole pipeline to stop, or you want the pipeline to continue but for awk to never call system again?

    – Jeff Schaller
    yesterday











  • Note that system() runs sh to interpret the command not bash. If you want to start bash to interpret bash specific code, you'll need to construct sh code that runs bash -c bash-specific-code-here where that bash-specific code will have to be quoted as per sh rules.

    – Stéphane Chazelas
    yesterday











  • @JeffSchaller I want the tail -F to continue watching the file but to run the system() command only once for each time matches are found, regardless of how many matches there are.

    – Jake
    9 hours ago












  • I'm having trouble putting together these two phrases: "run the system() command once" -- and -- "each time matches are found, regardless of how many matches there are". Do you want the command run for the first match, and that first match only?

    – Jeff Schaller
    9 hours ago











  • Yes, for the first match only.

    – Jake
    9 hours ago












  • 2





    after you calll system("command") you want the whole pipeline to stop, or you want the pipeline to continue but for awk to never call system again?

    – Jeff Schaller
    yesterday











  • Note that system() runs sh to interpret the command not bash. If you want to start bash to interpret bash specific code, you'll need to construct sh code that runs bash -c bash-specific-code-here where that bash-specific code will have to be quoted as per sh rules.

    – Stéphane Chazelas
    yesterday











  • @JeffSchaller I want the tail -F to continue watching the file but to run the system() command only once for each time matches are found, regardless of how many matches there are.

    – Jake
    9 hours ago












  • I'm having trouble putting together these two phrases: "run the system() command once" -- and -- "each time matches are found, regardless of how many matches there are". Do you want the command run for the first match, and that first match only?

    – Jeff Schaller
    9 hours ago











  • Yes, for the first match only.

    – Jake
    9 hours ago







2




2





after you calll system("command") you want the whole pipeline to stop, or you want the pipeline to continue but for awk to never call system again?

– Jeff Schaller
yesterday





after you calll system("command") you want the whole pipeline to stop, or you want the pipeline to continue but for awk to never call system again?

– Jeff Schaller
yesterday













Note that system() runs sh to interpret the command not bash. If you want to start bash to interpret bash specific code, you'll need to construct sh code that runs bash -c bash-specific-code-here where that bash-specific code will have to be quoted as per sh rules.

– Stéphane Chazelas
yesterday





Note that system() runs sh to interpret the command not bash. If you want to start bash to interpret bash specific code, you'll need to construct sh code that runs bash -c bash-specific-code-here where that bash-specific code will have to be quoted as per sh rules.

– Stéphane Chazelas
yesterday













@JeffSchaller I want the tail -F to continue watching the file but to run the system() command only once for each time matches are found, regardless of how many matches there are.

– Jake
9 hours ago






@JeffSchaller I want the tail -F to continue watching the file but to run the system() command only once for each time matches are found, regardless of how many matches there are.

– Jake
9 hours ago














I'm having trouble putting together these two phrases: "run the system() command once" -- and -- "each time matches are found, regardless of how many matches there are". Do you want the command run for the first match, and that first match only?

– Jeff Schaller
9 hours ago





I'm having trouble putting together these two phrases: "run the system() command once" -- and -- "each time matches are found, regardless of how many matches there are". Do you want the command run for the first match, and that first match only?

– Jeff Schaller
9 hours ago













Yes, for the first match only.

– Jake
9 hours ago





Yes, for the first match only.

– Jake
9 hours ago










1 Answer
1






active

oldest

votes


















0














From current output what you provided from my understanding you want to remove duplicates

pipeline_previous_command|awk 'if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/


Suppose if you want ouput as output which mentioned above



raveen:~$ pipeline_previous_command | awk '/W.0028/if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/





share|improve this answer























  • Yes, remove duplicates of SV.W match. I'm not understanding how to work this into my current script, however. Does it go after the getline; if (/SV.W/) command?

    – Jake
    7 hours ago










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Jake is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508173%2frun-bash-command-from-awk-system-only-once%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














From current output what you provided from my understanding you want to remove duplicates

pipeline_previous_command|awk 'if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/


Suppose if you want ouput as output which mentioned above



raveen:~$ pipeline_previous_command | awk '/W.0028/if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/





share|improve this answer























  • Yes, remove duplicates of SV.W match. I'm not understanding how to work this into my current script, however. Does it go after the getline; if (/SV.W/) command?

    – Jake
    7 hours ago















0














From current output what you provided from my understanding you want to remove duplicates

pipeline_previous_command|awk 'if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/


Suppose if you want ouput as output which mentioned above



raveen:~$ pipeline_previous_command | awk '/W.0028/if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/





share|improve this answer























  • Yes, remove duplicates of SV.W match. I'm not understanding how to work this into my current script, however. Does it go after the getline; if (/SV.W/) command?

    – Jake
    7 hours ago













0












0








0







From current output what you provided from my understanding you want to remove duplicates

pipeline_previous_command|awk 'if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/


Suppose if you want ouput as output which mentioned above



raveen:~$ pipeline_previous_command | awk '/W.0028/if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/





share|improve this answer













From current output what you provided from my understanding you want to remove duplicates

pipeline_previous_command|awk 'if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/
/O.CON.KFFC.SV.W.0021.000000T0000Z-190315T0015Z/


Suppose if you want ouput as output which mentioned above



raveen:~$ pipeline_previous_command | awk '/W.0028/if(!seen[$1]++)print $1'

/O.NEW.KBMX.SV.W.0028.190314T2350Z-190315T0030Z/






share|improve this answer












share|improve this answer



share|improve this answer










answered 7 hours ago









Praveen Kumar BSPraveen Kumar BS

1,6471311




1,6471311












  • Yes, remove duplicates of SV.W match. I'm not understanding how to work this into my current script, however. Does it go after the getline; if (/SV.W/) command?

    – Jake
    7 hours ago

















  • Yes, remove duplicates of SV.W match. I'm not understanding how to work this into my current script, however. Does it go after the getline; if (/SV.W/) command?

    – Jake
    7 hours ago
















Yes, remove duplicates of SV.W match. I'm not understanding how to work this into my current script, however. Does it go after the getline; if (/SV.W/) command?

– Jake
7 hours ago





Yes, remove duplicates of SV.W match. I'm not understanding how to work this into my current script, however. Does it go after the getline; if (/SV.W/) command?

– Jake
7 hours ago










Jake is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Jake is a new contributor. Be nice, and check out our Code of Conduct.












Jake is a new contributor. Be nice, and check out our Code of Conduct.











Jake is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508173%2frun-bash-command-from-awk-system-only-once%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown