Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Run this grep every 10 minutes and do something based on the output

$
0
0
OS : Red Hat Linux 6.4
Shell : Bash

We have a file called status.txt which will have only 1 line. The content will be the string "Processing" for most of the day.

Code:

# cat status.txt
Processing
#

I want to write a shell script (notify.sh) which will be executing a grep every 10 minutes .

Once the script is executed , it should do the following


1. run a grep command every 10 minutes and check if the content of status.txt is anything other than "Processing" .

2. If the status.txt file has anything other than the string " Processing " (ie. grep -v "Processing" ) then it should echo "Completed". Actually in my real business scenario If the status.txt has anything other than "Processing" then a mail needs to be send out using Linux's mail command. But, for our testing purpose an echo "completed" should do .


3. Stop the execution of the notify.sh script (exit) after grep command managed to find anything other than the string " Processing " and printed " Complete " .

Note: I don't this to be invoked via a cronjob because in my real world scenario this logic has to be incorported as a subsection of a much bigger script. :)

Any idea how I can write this piece of code ?

Viewing all articles
Browse latest Browse all 16232

Trending Articles