LinuxQuestions.org
Register a domain and help support LQ
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 11-11-2010, 04:23 PM   #1
montblanc
LQ Newbie
 
Registered: Feb 2008
Posts: 7

Rep: Reputation: 0
Post 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
 
Old 11-11-2010, 05:03 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Read

man mailx

and look up on the WEB

shell redirection stderr
.
 
Old 11-11-2010, 10:06 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by montblanc View Post
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).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
NFS Large File Copies Fail - Error writing to file: Input/output error deck- Linux - Server 7 07-27-2013 12:14 PM
[SOLVED] How to direct standard output from find command dyq Programming 3 03-26-2010 04:55 PM
can't capture 'at' command standard output to a file bartoni Linux - General 3 02-28-2006 04:52 PM
How do I forward standard and error output into same file? ivj Linux - Software 5 07-19-2005 09:30 PM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 03:07 PM


All times are GMT -5. The time now is 09:18 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration