LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Find command with standard error output and mail error file (http://www.linuxquestions.org/questions/programming-9/find-command-with-standard-error-output-and-mail-error-file-843752/)

montblanc 11-11-2010 03:23 PM

Find command with standard error output and mail error file
 
Hi Linux Folks:

We have the following issue:

We make everyday a DB Mysql backup on Linux redhat Enterprise. We are using a bash shell script (and putting it in the crontab) to execute it automatically everyday. We added a line to this script telling, once the backup has completed, to find old backup files (stored on hard disk after each backup) older than x days to remove them. We use the find command (search for file type) with the mtime option and in combination with rm command. Everything runs ok but we also want to add some new code to the same line: If find command cannot find anything or fails, for example if it cannot delete file or fails, send the error message (standard error output) to an error file (like error000001 and increasing) and mail the errorxxxx file to an email address for example to admin@companyname.com. What would be the code for this issue to add it to our find command in the same bash shell script??

please help, thx in advance

Sergei Steshenko 11-11-2010 04:03 PM

Read

man mailx

and look up on the WEB

shell redirection stderr
.

catkin 11-11-2010 09:06 PM

Quote:

Originally Posted by montblanc (Post 4156147)
If find command cannot find anything or fails, for example if it cannot delete file or fails

Not so easy because find does not set a non-zero return code on failing to find files, only on some internal error. To implement as you want you will have to move to a two step procedure 1) running find to generate a list of files (and error trap the list not meeting expectations) and 2) remove each file in the list (and error trap remove failures).


All times are GMT -5. The time now is 12:09 PM.