Note that there are some explanatory texts on larger screens.

plurals
  1. POBash script to count the number of occurances of a string in a file
    text
    copied!<p>I have this function in my Bash script</p> <pre><code> if [ $numberOne -gt 10 ] then echo "$numberOne has occurred over 10 times" echo "email me numberOne" elif [ $numberTwo -gt 4 ] then echo "$numberTwo has occurred over 4 times" echo "email me numberTwo" elif [ $numberThree -gt 4 ] then echo "$numberThree has occurred over 4 times" echo "email me numberThree" elif [ $numberFour -gt 5 ] then echo "$numberFour has occurred over 5 times" echo "email me numberFour" else echo "nothing found yet" exit fi } </code></pre> <p><strong>Info</strong>: I am port checking. I run a script every minute. When a port is found to be used I write it to a file and then read the file. The number of times it's found equates to minutes. 4 times is 4 minutes, I want to know if the port is active more that a number of minutes.</p> <p><strong>What I want to do:</strong></p> <p>3 numbers will populate a file. At some point one of them will be present more than 4 times and then the rest will also appear. At that point I want an alert when the first of them occurs or [all of them after the first occurrence]. Ideally the alert will be like this: "NumberOne has been open for 4 minutes". And after 1 minute it will be "5 minutes"-until I stop it or a threshold is reached, I don't know yet.</p> <p>The problem: The problem here is that when NumberOne occurs more than 10 times AND NumberTwo occurs 4 times after that it only echoes NumberTwo.</p> <p>I thought I could use <code>continue</code> after each <code>then</code>, but I can't!</p> <p>Also: my NumberOne variable. <code>NumberOne=$(grep -wc "port=51555" monitor.txt)</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload