![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Redirect Standard Output Multi-Process | djodjo | High Level Programming | 5 | 10-01-2008 05:09 AM |
| [BASH] redirect standard error and use it inside | Pescator | Shell Programming and Scripting | 2 | 03-03-2008 09:20 AM |
| Question from a newbie. How to redirect standard output | ndemos | UNIX for Dummies Questions & Answers | 1 | 07-27-2007 10:28 AM |
| redirect standard error into log file | epall | UNIX for Dummies Questions & Answers | 7 | 05-09-2006 06:29 AM |
| Error: Internal system error: Unable to initialize standard output file | firkus | UNIX for Dummies Questions & Answers | 2 | 10-25-2005 03:23 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
redirect only the standard error output to mail
I'm writing a script using file descriptor 2 (std error) to send an email only if the command fails or errors out but the script always emails me irrepective of whether it fails or not. It will not email the /tmp/check.error file output if doesn't error out just the mail with the subject "Cannot run check script on machB".
Any suggestions would be really appreciated. Thanks ###(Note: I have a mail problem with the one on 4th line, the other one works OK) ========================================================================================== #!/bin/ksh echo "" >> /tmp/sync.error rsync -goptvz -e ssh /var/sync.all machB:/var/sync.all 2>>/tmp/sync.error ssh -l root machB '/usr/local/check' 2>>/tmp/check.error | mail -s "Cannot run check script on machB" email@removed if [ $? = 0 ] then date +"%D %T:$script Successfully executed." >> /dev/null else date +"%D %T:$script Unsuccessfully executed." >> /tmp/sync.error date +"%D %T: Exiting script." >> /tmp/sync.error mail -s "Cannot sync the sync.all file to machB, plz. look at /tmp/sync.error" email@removed < /tmp/sync.error exit 1 fi date +"%D %T: Sync of printcap.all file completed." >> /tmp/sync.error |
|
||||
|
A generic way to handle any errors the script would be to get rid of your return code logic and
put this at the top of your script. Remove the piped mail statement also. Code:
trap 'mail -s "Error on line $LINENO; rc=$?" email@address </tmp/sync.error >/dev/null' ERR Code:
ssh -l root machB '/usr/local/check' 2>>/tmp/check.error | mail -s "Cannot run check script on machB" email@removed Code:
ssh -l root machB '/usr/local/check' 2>>/tmp/check.error || mail -s "Cannot run check script on machB" email@removed </tmp/check.error >/dev/null Last edited by frank_rizzo; 12-26-2007 at 09:30 PM.. |
|
||||
|
redirect only the standard error output to mail
Trying to setup rsync backup in the same fashion, but having much more limited knowledge than you gentlemen about shell scripts, can either of you give me an example of the 'finished' script you are talking about that is fully functional?
I am setting up a server that will use the rsync command and ssh to backup from local directories to an account at rsync.net and need to have emails sent to me if it fails. Thanks. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|