If file contains string do..else do..end


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If file contains string do..else do..end
# 1  
Old 12-26-2014
If file contains string do..else do..end

Hi,

I have a script that runs a sql and outputs it in a temp file. That file is emailed to a distribution group hourly. How can I modify it to email only if a string is present in the file?

Code:
$ORACLE_HOME/bin/sqlplus -s '/as sysdba' @$SCRPTDIR/example-01.sql $OUTFILE
/bin/mail -s "$1 example subject in email  `date` " admin@example.com < $OUTFILE
exit

The last line is email 'output file' to admins and I want to change it to email output file to admins IF it contains the string 'example' in it.

---------- Post updated at 12:14 PM ---------- Previous update was at 11:34 AM ----------

Okay I figured it out...

Code:
if grep -iFq "string" $file_name
       then /bin/mail -s "subject in email" admin@example.com < $file_name
fi

# 2  
Old 01-02-2015
Sometimes silence is not reliability, so you might want it to send unconditionally, once a day, just to show it is running. You can set a marker file when you send and if it is a day old, send an "I am alive" message. Or, send a summary at midnight of all the emails for the day.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search a String between start and end of a block in a file

Hi, I have a scenario where I want to display the output based on the pattern search between the start and end of a block in a file, we can have multiple start and end blocks in a file. Example give below, we need to search between the start block abc and end block def in a file, after that... (5 Replies)
Discussion started by: G.K.K
5 Replies

2. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

3. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

4. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

5. Shell Programming and Scripting

Append the end of each line in a file with a given string

Hi friends, I have a file containing many lines as follows. M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\ADBasicView.java@@\main\v6.4.0_pit_a I would like to append the string "\0" at the end of each line in the file. The output should look... (10 Replies)
Discussion started by: nmattam
10 Replies

6. Shell Programming and Scripting

Append a string at the end of every line in a file

Hi Friends, I have a file with many lines as shown below. /START SAMPLE LINE/ M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\port\Post.java@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\switchview\View.java@@\main\v6.4.0_pit_a /END SAMPLE LINE/ I... (1 Reply)
Discussion started by: nmattam
1 Replies

7. Shell Programming and Scripting

Appending string at the end of the file

Hello, I wanted to append 'XYZ' at the end of the text file. How can i do this? I searched the forums and i am not getting what i want. Any help is highly appreciated. Thanks (2 Replies)
Discussion started by: govindts
2 Replies

8. Shell Programming and Scripting

How can I append a string at the end of a line in a file

Hi, guys. I have one question: I have a file called "group", the contents of it is below: ******************************** ... test:x:203: sales:x:204: repair:x:205: research:x:206:brownj ... *********** Now I want to add string ",sherrys" at the end of "research:x:206:brownj", so... (5 Replies)
Discussion started by: daikeyang
5 Replies

9. UNIX for Advanced & Expert Users

Read text file from a specified string to the end

Hi All, I like to read the log file from specific time to end of the file. eg: message date and time message 1 date and time1 message 2 EOF I want to read all the text (Messages) after date and time to end of the file. Please let me know the UNIX command to perform this?. Thanks,... (9 Replies)
Discussion started by: bsrajirs
9 Replies

10. Shell Programming and Scripting

How to insert a string at the end of a file read

Hi, This thread is an extension of the post I posted in another folder for Unix Dummies. I am actually trying to read all the files in a folder, let say folder A. There are alot of .txt files in this folder where I have sed them and translate to numeric elements. For example:- I have... (5 Replies)
Discussion started by: ahjiefreak
5 Replies
Login or Register to Ask a Question