Redirect script output to a file and mail the output

Hi Guys,

I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts.
I used below but it is not working:

 
OFILE=/home/home1/report1
 
echo "report1 details" > $OFILE
=/home/home1/1.sh > $OFILE
echo "========================================================================================================================================" > $OFILE
echo "report2 details" > $OFILE
=/home/home1/2.sh > $OFILE
echo "========================================================================================================================================" > $OFILE
echo "report3 details" > $OFILE
/home/home1/3.sh > $OFILE
echo "========================================================================================================================================" > $OFILE
cat $OFILE | mail -s "Verification" abc@gmail.com

i am just getting the output of three scrips separately meaning individual scripts are ruuning but not getting the output in one mail as below.

 
OUTPUT should be as below:
 
report1 details
The total no of difference in previous day report and current day report is 0 records
 
 
========================================================================================================================================"
 
report2 details:
The total no of difference in previous day report and current day report is 1 records
 
 
========================================================================================================================================"
 
report3 details:
The total no of difference in previous day report and current day report is 1 records

Hello,

It will not put that data from file named

 OFILE 

in your code.

As command

 mailx 

is coming at last and you are not concating the data into the file you are just overwriting the data by doing

> $OFILE 

to it.

Please use

 =/home/home1/1.sh >> $OFILE 

to save it from overwriting and use it then.

Thanks,
R. Singh

using home/home1/1.sh >> $OFILE is also not working..
I am getting completely blank mail with subject line Verification.
Not even echo is working..
As soon as i run the script i get three emails giving the output of 3 script because i have use mail command in those scripts also and 4th mail gwenerated blank email with subject line only.

---------- Post updated at 03:50 PM ---------- Previous update was at 03:38 PM ----------

I just want to get the output of 3 scripts in one mail.

What is this: =/home/home1/1.sh ?
Try

echo "report1 details" > $OFILE 
/home/home1/1.sh >> $OFILE 
echo "========================================================================================================================================" >> $OFILE 
echo "report2 details" >> $OFILE 
/home/home1/2.sh >> $OFILE 
echo "========================================================================================================================================" >> $OFILE 
echo "report3 details" >> $OFILE 
/home/home1/3.sh >> $OFILE 
echo "========================================================================================================================================" >> $OFILE 
cat $OFILE | mail -s "Verification" abc@gmail.com

Or use a grouping command and avoid creating a temporary file:

{
echo "report1 details"
/home/home1/1.sh
echo "========================================================================================================================================"
echo "report2 details"
/home/home1/2.sh
echo "========================================================================================================================================"
echo "report3 details"
/home/home1/3.sh
echo "========================================================================================================================================"
} | mail -s "Verification" abc@gmail.com
1 Like

The problem is /home/home1/2.sh >> $OFILE is not working.
Script 2.sh output should be redirected to $OFILE which is not happening.
When i am running the command

./2.sh>>filename 

it is not working.
Inside 2.sh script I am redirecting the output of this script to a filename1 and then mailing the output.

That statement of yours is a bit difficult to believe. Why should a plain redirection stop working? What's your shell/system?

If your three scripts send individual mails themselves, then you can't combine them.
Perhaps they have an option to print to stdout instead?