Bash Script Locate Word Failed

I'm using CentOS 7 and I would like to know of a way to read each line and search for a specific word. For example, if it finds the word "Fail" it sends it to a variable, and pipes it to a folder on the network.

What would be the best way in making this work in a Linux environment?
I wrote a script that connects to ESXi host via SSH, and when connection is made to ESXi server, the script runs a command to check RAID 5 hard drive status.

I created cron job to initiate script to run everyday at a certain time and sends me an email displaying RAID 5 disk drive status. I am very satisfied with my results.

Now, I would like to add to my script. So when a hard drive does fail! I can be notified every hour. We have an application on the network, that we can dump text files in and as a result sends an email out every hour.

With that said. I would like new script to read each line and look for the word "fail" and when it finds the word, it will send it to a file on the network.

So far I was able to run a command and locate the word fail. But, I don't know of a way to send results to a file on the network. The command I use is this:

#find /tmp -type f -name "*.txt" -exec grep -l "failed" {} \+

The reason why I don't want to modify my current script to run RAID checks every hour is because we have more than ten ESXi host servers.

I would not like to receive fifteen emails every hour and look for a failed hard drive.

It's better to receive one email indicating a failed disk drive. I am open to new creative ideas.

Welcome to the forum.

Unfortunately, this is quite vague a specification. No indication of your setup is made beyond "CentOS 7". Whatever info is found in your script, you want to "pipe it to a folder on the network", "send it to a file on the network", "sends me an email". What EXACTLY is your question? You are "open to new creative ideas" - give people in here a basis to become creative upon.

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

1 Like