Results 1 to 3 of 3
Hi All, I'm fairly new to bash scripting, so thanks in advance for your help and if this question is more appropriate somewhere else please let me know.
I'm trying ...
- 03-12-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 2
Bash script to execute and email job status
Hi All, I'm fairly new to bash scripting, so thanks in advance for your help and if this question is more appropriate somewhere else please let me know.
I'm trying to write a script that will execute a job, email both the standard out and error and weather or not it was successfully completed. I think it would be fairly simple if I just redirected the standard out and error to a file but I'm trying to avoid that because I will have potentially hundreds of jobs running at the same time and I don't want them to be overwriting each other. So I've tried to just pipe the output to mail.
The problem is the command always exits with a zero because the mail program executes successfully even if the original program failed. Any ideas? Here's what I got so far:
#! /bin/bash
myCommand=$1
eval $myCommand 2>&1 | mail -s "Executed: $myCommand" myEmail
if [ $? = 0 ]
then
echo "Successful: $myCommand"
#mail -s "Successful: $myCommand" myEmail
else
echo "FALIURE: $myCommand"
#mail -s "FALIURE: $myCommand" myEmail
fi
exit
- 03-12-2009 #2
Try putting a && behind the first command.
"A graphical user interface is just a mask. What lies beneath is what matters."
- 03-12-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 2
I figured it out, needed to use the following:
exitStatus=${PIPESTATUS[0]}


Reply With Quote