Operating System - HP-UX
1834272 Members
97940 Online
110066 Solutions
New Discussion

Help - I am looking for a script

 
SOLVED
Go to solution
Nick D'Angelo
Super Advisor

Help - I am looking for a script

that will look in sub directories for certain files and then email them to me.

The pattern that I am looking for is dbname.lg.

or better than mailing them, how about we back them up but this would require the renaming of the files as they are db backup log files with the same name.
Always learning
13 REPLIES 13
Hai Nguyen_1
Honored Contributor

Re: Help - I am looking for a script

# find -name dbname.lg | xargs mailx user@domain.com

will email you a list of dbname.lg files.

Hai
Nick D'Angelo
Super Advisor

Re: Help - I am looking for a script

Almost but the directory structure is the problem

I have the following files in these directories
/bi/parking/02/Feb/02/iscan.lg
/bi/parking/02/Feb/03/iscan.lg
/bi/parking/02/Feb/04/iscan.lg

The script that you gave me comes back with a no message error.

Thanks.
Always learning
Nick D'Angelo
Super Advisor

Re: Help - I am looking for a script

Sorry, I need the actuall files emailed to me not just the list.
Always learning
Pete Randall
Outstanding Contributor

Re: Help - I am looking for a script

Nick,

Something like this:

for FILE in `find /bi/parking -name iscan.lg`
do
elm -s "WhatEver" Nick@xxx.com < $FILE
done

I think that should give you what you're looking for.

Pete

Pete
Nick D'Angelo
Super Advisor

Re: Help - I am looking for a script

Hai and Pete,
thanks for your help.

Pete especially. It is a little heavy on the system load with a zillion sendmail requests, but I think it works.

Thanks again.

Nickd
Always learning
Shannon Petry
Honored Contributor

Re: Help - I am looking for a script

Or something with mailx for subject like
# for FILE in `find /dir -name "dbname.lg" -print` ; do
cat $FILE | mailx -s $FILE user@somewhere
done

Regards,
Shannon
Microsoft. When do you want a virus today?
Hai Nguyen_1
Honored Contributor

Re: Help - I am looking for a script

Ok. this is a modified version.

#!/bin/sh

find -name dbname.lg | while read FILE;
do
mailx -s "$FILE" user@domain.com < $FILE
done
Pete Randall
Outstanding Contributor
Solution

Re: Help - I am looking for a script

Nick,

You could concatenate all the files into one big file and just mail that one. Would that work for you?

Pete

Pete
Pete Randall
Outstanding Contributor

Re: Help - I am looking for a script

Nick,

Or - for that matter - we could pursue your backup idea. How and where do you want to back them up and what to you want done with the originals?

Pete

Pete
Rich Wright
Trusted Contributor

Re: Help - I am looking for a script

Here is script code to put all of the files into a single email.
/usr/lib/sendmail -t << __EnD__
To: $TO
Cc: $CC
Bcc: $BCC
Subject: $SUBJECT


$(echo $BODY)

$(find /work -name 'dbname.lg' -exec uuencode {} {} \;)

__EnD__

Alan Riggs
Honored Contributor

Re: Help - I am looking for a script

Why not use a single sendmail with multiple attachments?

sendmail target@domain << END
Subject: changed files
$(find . -name "pattern" -exec uuencode {} {} \;)
done

Nick D'Angelo
Super Advisor

Re: Help - I am looking for a script

Points to everyone - but Pete's solution was perfect.

Thank you !!
Always learning
Nick D'Angelo
Super Advisor

Re: Help - I am looking for a script

Sorry, me again.

I for some reason, can not get my head around this.

It would be preferred if the files were concatenated to one big file.

Everything I try, simply lists the files.

The problem is my directory structure of ..../02/May/01/iscan.log and ..May/02/iscan.lg

for every day.

My apologies for re-posting.
Always learning