Sending find command results to email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending find command results to email
# 1  
Old 04-26-2007
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 script this so it runs as a cron job every 10 minutes. I would appreciate any help. Thanks in advanced.
# 2  
Old 04-26-2007
1. sendmail to send message, title and destination in command line, content in stdin.

cat message | /usr/lib/sendmail -s "title" foo@bar

2. cron, use crontab to set up job

Depending on the system you may have to find the correct version of "sendmail" or use "mailx".
# 3  
Old 04-26-2007
The problem is.....

# find home/folder -cmin -10 | echo <email message> |mutt -s <email subject> <email address>

This always send an email whether or not any files are found that were created in the last 10 minutes. I want it to only send an email if it finds a file created in the last 10 minutes.

Thanks again for any help.
# 4  
Old 04-27-2007
This worked but.....

This works but it's probably sloppy and the only way so far I could do it (OK I'm new)
# find files created in last 10 minutes and, if found, email an alert

#!/bin/sh

find /home/folder -cmin -10 >test.txt #find files created in last 10 minutes and output to test.txt

then

if [ -s /folder/folder/test.txt ] # is text.txt > 0?

echo <email message> |mutt -s <subject> <email address>

else
echo stop

fi
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find with rm command gives strange results

I want to remove any files that are older than 2 days from a directory. It deletes those files. Then it comes back with a message it is a directory. What am I doing wrong here? + find /mydir -mtime +2 -exec rm -f '{}' ';' rm: /mydir is a directory (2 Replies)
Discussion started by: jtamminen
2 Replies

2. Shell Programming and Scripting

ksh script find command not printing any results

Hello, Hitting a wall on this one. When at the command prompt it works fine: # find /home/testuser -name 'PAINT*canvasON.txt' /home/testuser/PAINT_canvasON.txt # pwd /home/testuser # ls -l PAINT*canvasON.txt -rw-r--r-- 1 root user 23 Feb 07 02:58 PAINT_canvasON.txt... (2 Replies)
Discussion started by: seekryts15
2 Replies

3. Shell Programming and Scripting

find + tar + gzip + uunecode/email --> in one command?

How to search for all files with matching strings --> find + tar + gzip + uunecode/email them in one command? I am sure there is a right way to pass list of files to tar, then compress tar file. Then send that as attachment using uuencode in one command.. Can we do that!? (3 Replies)
Discussion started by: kchinnam
3 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Find command gave unexpected results

Hi, I recently executed a find command that caused unexpected permission changes and we had to do a full system restore. Can someone please explain what this command would do? find /staging/admin/scr * -exec chmod 755 '{}' + It caused file permissions inside / to be modified strangely. ... (1 Reply)
Discussion started by: poornima
1 Replies

6. Shell Programming and Scripting

sending output of command via email

Hi all i want to send the output of a command by email, i have done this <comand> | mail -s <subject> <email address> which works well, but if the command retunrs noting then i just get a blank email, is there a way to stop this thanks Adam (4 Replies)
Discussion started by: ab52
4 Replies

7. Shell Programming and Scripting

Place 'find' results within TeX command

Hi, In an effort to collect all my .java-files and place them in a LaTeXfile (using the listings environment of latex), i tried to use ex. So what i have now is: find . -name "*\.java" > latex ex latex <<HERE %s/\(.*\)/\\lstinputlisting{\1} wq HERE So i try to escape the '\' with... (1 Reply)
Discussion started by: HannesBBR
1 Replies

8. UNIX for Dummies Questions & Answers

sorting files with find command before sending to text file

i need help with my script.... i am suppose to grab files within a certain date range now i have done that already using the touch and find command (found them in other threads) touch -d "$date_start" ./tmp1 touch -d "$date_end" ./tmp2 find "$data_location" -maxdepth 1 -newer ./tmp1 !... (6 Replies)
Discussion started by: deking
6 Replies

9. Shell Programming and Scripting

edit results of a find command

Hi Purpose is to have a utility command to find and edit files . I tried a function like the following in my .profile file function vifind(){ find . -name $1 -print -exec vi {} \; } Is this correct? is there a better way to do it? I see this behaving a bit strange in case of AIX, and... (6 Replies)
Discussion started by: grep_whoami
6 Replies
Login or Register to Ask a Question