LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 03: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, 04:03 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Read

man mailx

and look up on the WEB

shell redirection stderr
.
 
Old 11-11-2010, 09:06 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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



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 10 08-01-2022 02:30 AM
[SOLVED] How to direct standard output from find command dyq Programming 3 03-26-2010 03:55 PM
can't capture 'at' command standard output to a file bartoni Linux - General 3 02-28-2006 03:52 PM
How do I forward standard and error output into same file? ivj Linux - Software 5 07-19-2005 08:30 PM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 02:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 AM.

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
Open Source Consulting | Domain Registration