LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2008, 05:50 PM   #1
basisvasis
LQ Newbie
 
Registered: Sep 2008
Posts: 2

Rep: Reputation: 0
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 so far.

Your help would be appreciated.
 
Old 09-12-2008, 02:14 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Show the combinations you've tried so far, and some representative example data.
 
Old 09-13-2008, 11:57 AM   #3
basisvasis
LQ Newbie
 
Registered: Sep 2008
Posts: 2

Original Poster
Rep: Reputation: 0
I have tried the following:But i get the error command LINE 7, PRINT: command not valid

#!/bin/bash
#set -x

if [[ $# = "0" ]]
then

print "USAGE: $0 [Search_Directory]"
exit 0

elif [[ ! -d ${1} ]]
then

print "$0 : Error, must provide a directory path to search for files modified in last 30 minutes!"
exit 1

else

SRCHDIR=${1}

fi

FOUNDARRAY=( $(find ${SRCHDIR} -mmin -30|xargs) )

for I in ${FOUNDARRAY[*]}
do

STR="$(grep -i "[mysearch_string_here]" ${I})"

if [[ ! -z ${STR} && -f ${I} ]]
then

echo "${STR}" | mailx -s "File: ${I} has the string" [my email address here]

fi

done
 
Old 09-13-2008, 12:23 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Use the echo command instead of print.

Is this an exercise to learn bash scripting, or are you just trying to create/find a utility that finds modified files less than 30 minutes?

Please place your code in [ code ] [ /code ] tags to maintain formatting - it is easier for others to read.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script find a line and the next line (grep?) metalx1000 Programming 5 07-24-2007 08:41 PM
Find and Grep in Script - almost there chess Programming 8 05-01-2007 09:15 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
Grep Syslog - email shell script voodoofxz Linux - Newbie 1 09-06-2005 04:27 PM
using find /grep gamor Linux - Newbie 14 04-13-2005 02:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration