echo "Files loaded with $(cat /var/tmp/script.X1.out)" | mail -s "Files loaded with return code" mailid
This script takes the output from script.X1.out file and appends the text "Files loaded with return code" and sends the email. Now what I want is to append Status as Success or Failure based on return code in the .out file. like as below.
if script.X1.out contains, Return code 0, then SUCCESS to be appended in the email.
if script.X1.out contains, Return code 2, then FAIL to be appended in the email.
Please help me build this piece of code. Kindly suggest .
Thanks,
Midhun
Thanks for your answer. I meant append is referring to content in the email. i.e I have to extract only from the .out file the return code of a ABC.sh script. that I'm handling in another code.
So basically,
"echo "Files loaded with $(cat /var/tmp/script.X1.out)" | mail -s "Files loaded with return code" mailid " -- this code gives the output(return code) from file and send email with subject in quotes.
All I want is
if script.X1.out contains, Return code 0, then SUCCESS to be appended after the first pipeline in the email content.
if script.X1.out contains, Return code 1, then WARNING to be appended after the first pipeline in the email content.
if script.X1.out contains, Return code 2, then FAIL to be appended after the first pipeline in the email content.
script.X1.out value always changes so i'm doing cat from it or i can change it to grep as you suggested. can you please help on the code for the above scenario.
Hi RudiC,
Can you please explain the above code what you replied. How does the above code fetch Return code from file and assign SUCCESS FAIL WARNING based on it ?
The first grep retrieves the line "Return Code n", the second extracts the number n which becomes the result of the "command substitution" which in turn serves as an index into the RT array:
0 ->Success
2 -> Failure