Bash Script Locate Word Failed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script Locate Word Failed
# 1  
Old 10-25-2017
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:

Code:
#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.

Last edited by SysAdminRialto; 10-25-2017 at 01:59 AM.. Reason: My sentance didn
# 2  
Old 10-25-2017
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.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

Script to locate date in filename

I am looking for a way to find a date in the file without using find. for example something like this: files=`ls |grep txt` YEST=`TZ="GMT+24" date +'%m-%d-%Y'|sed 's/^0//g' |sed 's/$/.txt/g'` YES1=`TZ="GMT+48" date +'%m-%d-%Y'|sed 's/^0//g' |sed 's/$/.txt/g'` if ]; then echo yes;else echo... (4 Replies)
Discussion started by: newbie2010
4 Replies

3. UNIX for Advanced & Expert Users

Tring to locate a script

Hello, We have a process on our Linux RedHat machine creating symbolic links and moving around some files from domain to domain. The issue is that the programmer has left a long time ago and nobody knows how the program is called, where it is and how the scheduling is setup. It runs every day for... (7 Replies)
Discussion started by: Indalecio
7 Replies

4. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

5. Shell Programming and Scripting

Bash script failed with expect on cisco routers

Hi all, I use a bash script which use expect to connect throught ssh and run command on a cisco router. The ssh connection with expect work fine, but the first command on the cisco router failed, I try to run the command in error by hand and it work fine... :( the first part of the script... (2 Replies)
Discussion started by: bedomon
2 Replies

6. Shell Programming and Scripting

Script to locate Thunderbird message filter

#!/bin/sh #Finds the directory where usually the message folder information is for Thunderbird. clear cd ~/ cd .thunderbird dir=$(dir) echo $dir echo "What is the name of your .default directory?" read userinput echo "Your Thunderbird Message Filter msgFilterRules.dat files are in the... (1 Reply)
Discussion started by: edcompsci
1 Replies

7. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

8. Solaris

BASH installation failed

Hi expert, Installation of Bash from sunfreeware failed on Solaris 2.5.1. Help ! # /usr/local/bin/bash ld.so.1: /usr/local/bin/bash: fatal: libsnprintf.so.1: open failed: No such file or directory Killed # (3 Replies)
Discussion started by: skully
3 Replies

9. Shell Programming and Scripting

script to locate servers

I am a newbie in shell scripting and I need to produce a script to work and achieve the following: 1) Look into the file /etc/defaultrouter , and store the value in it 2) If the value is a number, go to LIST and print out the second column corresponding to the value.(eg London) 3) If the... (5 Replies)
Discussion started by: ibroxy
5 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question