Unix Script to email grepped results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Script to email grepped results
# 1  
Old 02-20-2011
Unix Script to email grepped results

I am following the tread number 81556 to grep a file and send the results in email.

Code:
#/bin/bash
/bin/grep -i 'invite sip' /var/log/asterisk/full 
if [ $? -eq 0 ] echo "found" |
mail -s 'invite sip' mail@gmail.com

When I just build it to grep and mail, it works fine. However, the if statement causes the script to error out. I get the following error:

Code:
./grep_email.sh: line 5: syntax error: unexpected end of file

I searched high and low and am stuck on this simple task. Any help is appreciated.
# 2  
Old 02-21-2011
Unexpected EOF is because it's looking for a then to match the if statement.

Try this (changes in green)
Code:
#/bin/bash
/bin/grep -i 'invite sip' /var/log/asterisk/full 
if [ $? -eq 0 ] 
then
    echo "found" | mail -s 'invite sip' mail@gmail.com
fi

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-21-2011
yea you gotta keep to the if/then or if/then/else...syntax. You need to specify what to do in the event the test (if) is true or false. Human speak: If something evaluates to true or false then do something in that event 'or else do something different'. If must be terminated by fi. If in fi out.
# 4  
Old 02-21-2011
Thank you! I tried the THEN statement but I guess it can't be on the same line as the IF statement. Next I will figure out how to include the results and have it pick up off where it left off on an active log.

Thank you.
# 5  
Old 02-21-2011
If you want to do a simple test on the one line just drop the if like this:

Code:
[ $? -eq 0 ] && echo found | mail -s 'invite sip' mail@gmail.com

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Executing of UNIX script using email

Dear Unix Leads, can you please let me know is it possible to execute a shell script in UNIX machine sending an email from outlook or gmail ? or is it possible to generate a token file in UNIX by sending email which we can indirectly use to trigger script your response on this is highly... (5 Replies)
Discussion started by: mirwasim
5 Replies

2. Shell Programming and Scripting

Postgre Query results as Email HTML table

Hello, I'm trying to send email from Greenplum query results as HTML table with status Red/Green Select Server, Last_Date from Table; Results Server, Last_Date Prod, 2018-04-09 Final email Output in HTML format Server Status LastDate Prod GREEN(BOX) 2018-04-09 (if... (2 Replies)
Discussion started by: krux_rap
2 Replies

3. Shell Programming and Scripting

UNIX script for consolidated email

Hi, I am working on the below script to get a disk usage report in email from multiple unix systems but the problem I am getting first email with 1 system and second email with 2 systems and finally third email with all 3 systems :) Can someone please let me know how I can get single email... (4 Replies)
Discussion started by: new2prog
4 Replies

4. UNIX for Dummies Questions & Answers

Emailing results of a pl sql procedure from UNIX shell script

Hello All, I am writing the below unix script to email the result of a small pl sql procedure: #!/bin/bash ORACLE_HOME=/opt/oracle/orcts/product/9.2.0; export ORACLE_HOME SQLPLUS=$ORACLE_HOME/bin/sqlplus sqlplus -s user/pass@Db_instance<<EOF set echo off set feedback off set pages 0... (9 Replies)
Discussion started by: Bunty bedi
9 Replies

5. Shell Programming and Scripting

Unix Shell Script to automate email alert

Hi all, I have a task on my plate which is of high priority. I need an automated email alert that checks FTP notices subdirectory on a daily basis and forwards any word files to a group of people. This word files gets created whenever there is an issue with FTP connectivity. Please help...... (1 Reply)
Discussion started by: stunnerz_84
1 Replies

6. UNIX for Dummies Questions & Answers

sql query results in unix shell script

Hi I want to get the a field from a SQL query into unix shell script variable. the whole situation is like this. 1. Opened a cursor to a table in DB2 databse. 2. Fetching individual rows with the help of cursor. 3. Each row has 4 fields. I want each of the field in individual shell... (1 Reply)
Discussion started by: skyineyes
1 Replies

7. Shell Programming and Scripting

Sending find command results to email

This is probably simple so forgive me... I just want to find all files in a folder created within the last 10 minutes... This is easy: # find /home/folder -cmin -10 If the find command locates any files created in the last ten minutes I want it to send an email alert. I just want to... (3 Replies)
Discussion started by: gardellap
3 Replies

8. Shell Programming and Scripting

send a message through email to 5 people using unix script?

Hi All, I want to send a message through email to 5 people in unix script. Please let me know, how to do it.Please do reply it is urgent.How to do it?Please reply.thanks! Thanks, Mary. (2 Replies)
Discussion started by: MARY76
2 Replies

9. Shell Programming and Scripting

sending email from KSH unix script.

Hi Need guidance on including code to mail a couple of files atached with some subject and mail body !!.. Thanks in advance (3 Replies)
Discussion started by: rosh0623
3 Replies

10. UNIX for Dummies Questions & Answers

need a unix script to let me know by email or pager when the filesystem is 80% full.

Does anyone have a script to check disk space usage. My backup directory keeps filling up with archivelog files and I need a script to let me know by email or pager when the filesystem is 80% full. Thank you! (1 Reply)
Discussion started by: jzjy0r
1 Replies
Login or Register to Ask a Question