Grep and Email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep and Email
# 1  
Old 09-17-2008
Grep and Email

Hello All,

I want to make a script which reads a files after every one hour and grep a pariticular word on it and if it finds it than email me on my email address. Please tell me how i start and if there is some example
available then please tell me the link.

One thing more that for the emailing purpose, do i have to configure mail server or mail client on my machine..

Please explain in detail..

Regards,
Waqas Ahmed
# 2  
Old 09-17-2008
Code:
#/bin/ksh
# this is myscript.sh
/usr/bin/grep -q 'particular word'  /path/to/somefile
if [ $? -eq 0 ]
    echo "particular word found in /path/to/somefile " | /usr/bin/mailx -s 'found it' \
        me@mymailaccount.com
fi

Make an entry in crontab to run 10 minutes after the hour every hour
Code:
10 * * * * /path/to/myscript.sh

Yes, you do need mail up and running.
[/code]
# 3  
Old 09-17-2008
Quote:
Originally Posted by jim mcnamara
Code:
#/bin/ksh


It is possible, though unlikely, that ksh is not installed.

There is nothing in the script that requires ksh., so it is better to use sh:

Code:
#!/bin/sh

Quote:
Code:
# this is myscript.sh
/usr/bin/grep -q 'particular word'  /path/to/somefile


On many systems grep is in /bin, not /usr/bin and your script will fail. There is no need to give the full path for standard commands.

Quote:
Code:
if [ $? -eq 0 ]
    echo "particular word found in /path/to/somefile " | /usr/bin/mailx -s 'found it' \
        me@mymailaccount.com


On some systems, the command may be mail rather than mailx. (And the comment about using the full path applies here, too.)
# 4  
Old 09-17-2008
Grep and Email

I want to use the mail command to send email from the command line like so:
Code:
mail -s "subject of email" emailaddress@whatever.com<textfile.txt

Can you please tell me do i have to turn on Sendmail for this.

My machine is connected to internet but below mail command is not working.

Code:
mail -s "subject of email" emailaddress@whatever.com<textfile.txt

i have to do just send email to my account. I dont want to receive anything, only sending email is my requirement.

Regards,
Waqas Ahmed
# 5  
Old 09-17-2008
[quote=wakhan;302237487]
My machine is connected to internet but below mail command is not working.

Code:
mail -s "subject of email" emailaddress@whatever.com<textfile.txt

What error do you get? Did you check logs?
# 6  
Old 09-17-2008
check /var/spool/mqueue

See if the message is sitting in there. There should be two files for each failed send attempt.
# 7  
Old 09-17-2008
Grep and Email

Final-Recipient: RFC822; khiomc@telecard.com.pk

Action: failed

Diagnostic code :SMTP; Domain of the sender address [email]root@localhost.localdomain does not exsist
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep a pattern & Email from latest logs

MyLOG: 2017/11/12 17:01:54.600 : Error: LPID: 3104680848 WRONG CRITERIA FOUND. tRealBuilder::Generate Output Required: If Ke word "WRONG CRITERIA FOUND" in latest log ( logs are regularly generating - real time) mail to us once mailed wait for 2 hours for second mail. mail subject... (3 Replies)
Discussion started by: vivekn
3 Replies

2. Homework & Coursework Questions

Search email addresses using grep command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Let's say if we have a file with a lot of information. For example: iiadam otterhedgehog kayleigh... (2 Replies)
Discussion started by: ForeignGuy
2 Replies

3. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

4. UNIX for Dummies Questions & Answers

grep command for email

May I know what is the command-line instruction to show all the subjects and authors of my emails contained in a directory by using egrep? Thanks! (2 Replies)
Discussion started by: marcuslki
2 Replies

5. Shell Programming and Scripting

Grep multiple instances and send email.

Removed (15 Replies)
Discussion started by: saisneha
15 Replies

6. UNIX for Dummies Questions & Answers

new to ldap, send email to a ou or group, and see a list from email client

hi, i'm running openldap on ubuntu 10.04, creating new items with apache directory studio (windows version). i use the ldap just as an address book to our small office (email clients are windows live mail 2009, 2011, microsoft outlook 2007 and 2010). a. i cant see a list of the contacts,... (0 Replies)
Discussion started by: V4705
0 Replies

7. Shell Programming and Scripting

Grep & EMail "HOW to quit ??? "

Hello All, I am using the below code to grep particular word from file and then emailing it through mail command. the problem is this that when i run the script so it stops and ask me for the mail body then it asks for cc: and then runs. I dont want to give body and cc: address, i just want... (1 Reply)
Discussion started by: wakhan
1 Replies

8. Shell Programming and Scripting

Script to find, grep and email

running a suse linux 10. I'm trying to write a script that searches for a file with certain name and that has been modified less than 30 minutes ago, then search for a certain string in that file and email this string out. I have tried different combinations of find, grep and email but no luck... (7 Replies)
Discussion started by: basisvasis
7 Replies

9. Gentoo

inserting grep -c value into an email subject

I am profoundly new to *nix, but had a project dropped in my lap that has sparked an interest, leading me here. I was tasked with daily sending one of our customers a listing of all the spam our filter blocked that was heading for them. Between Google and I; I discovered the Server is running... (3 Replies)
Discussion started by: GrendelPrime
3 Replies

10. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies
Login or Register to Ask a Question