Operating System - HP-UX
1748224 Members
4479 Online
108759 Solutions
New Discussion юеВ

How to search an email thru a file on the whole server

 
Fenglin
Regular Advisor

How to search an email thru a file on the whole server

Can I have a command to search an email in a file on the whole server?

Please advice.

Regards
Feng Lin
7 REPLIES 7
Dennis Handly
Acclaimed Contributor

Re: How to search an email thru a file on the whole server

root can use grep to search all of the files in /var/mail/. If a user has mail clients that copy the mail from there to mail folders in his home directory, you would also have to look there too.

Do you have more details on what you are looking for and where?
Fenglin
Regular Advisor

Re: How to search an email thru a file on the whole server

Hi

My colleague is going on leave..So need to remove her email inside some jobs which contain her email address but we do not know where the files are located on the server. I am expecting something like the following

find / -name "*.pl" |grep xxxx@yahoo.com.sg

I am just quoting an example. Is this correct?

Regards
Feng Lin
Dennis Handly
Acclaimed Contributor

Re: How to search an email thru a file on the whole server

>remove her email inside some jobs which contain her email address

Ah. The first place to look is the cronjobs:
/var/spool/cron/crontabs/*

To look for all .pl scripts:
find / -name "*.pl" -exec grep xxxx@yahoo.com.sg +
Fenglin
Regular Advisor

Re: How to search an email thru a file on the whole server

Hi Dennis

The command for pl files is not working. Did you try it out yourself?

Regards
Feng Lin
VK2COT
Honored Contributor

Re: How to search an email thru a file on the whole server

Hello,

Dennis is actually correct., That syntax
for find(1m) works on HP-UX.

So, both these versions would work on HP-UX:

find / -name "*.pl" -exec grep xxxx@yahoo.com.sg +

find / -name "*.pl" -exec grep xxxx@yahoo.com.sg {} \;

The latter format is probably the one you are
used to...

Cheers,

VK2COT
VK2COT - Dusan Baljevic
bright image
Frequent Advisor

Re: How to search an email thru a file on the whole server

I would add a -print to the end of the find command to print the path and name of the file the email address was found in otherwise you will just end up with a list of the matching lines and no file names.

You could also add -type f if you want to ensure you only search regular files.

For example...

find / -type f -name "*.pl" -exec grep xxxx@yahoo.com.sg + -print
bright image
Frequent Advisor

Re: How to search an email thru a file on the whole server

For future reference I think it is good practice to add a line like the following to end of any messages that is generating and sending emails automatically.

echo "\nThis is an automated message generated by script $0 on server $(uname -n)\n"

That way it is easy to find the source of the message when required.