Echo print in different lines within email sent by Cron job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Echo print in different lines within email sent by Cron job
# 1  
Old 11-08-2010
Echo print in different lines within email sent by Cron job

Hi all,

I think this could have a simple solution, just I canīt get it so far.
I have the script below that includes several echo commands in order
to show that every part of the script have been executed. A cron job
executes this script and when is completed the output is sent by email.


Code:
#!/usr/bin/sh

echo "+++++++++++++++++++++++++++++++++++++++++++++"
echo "+++++++++++++  PROCESS PART 1   +++++++++++++"
echo "+++++++++++++++++++++++++++++++++++++++++++++"

FILE1=$(ls)
for each in $FILE1
do echo "Processing $each...\n";
done

echo "+++++++++++++++++++++++++++++++++++++++++++++"
echo "+++++++++++++  PROCESS PART 2   +++++++++++++"
echo "+++++++++++++++++++++++++++++++++++++++++++++"

FILE2=$(ls *.txt)
for each in $FILE2
do echo "Processing $each...\n";
done

echo "+++++++++++++++++++++++++++++++++++++++++++++"
echo "+++++++++++++++   WORK DONE  ++++++++++++++++"
echo "+++++++++++++++++++++++++++++++++++++++++++++"

I only want to receive the output sent by the Cron job
correctly formatted(each echo print in different line)
as shown below:


Code:
+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++  PROCESS PART 1   +++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++
Processing filename1.txt
Processing filename2.txt
Processing filename3.txt
+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++  PROCESS PART 2   +++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++
Processing filename4.txt
.
.
.
Processing filenameN.txt
+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++   WORK DONE  ++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++

I`ve tested adding \n at the end of every echo command but doesn`t seem to work.
The current output I get in the email received is continuos echo prints like this:


Code:
+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++  PROCESS PART 1   +++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++
Processing filename1.txt...\n Processing filename2.txt...\n Processing filename3.txt...\n 
+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++  PROCESS PART 2   +++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++
Processing filename4.txt...\n ....Processing filenameN.txt...\n 
+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++   WORK DONE  ++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++

May somebody help me saying how can I get the echo prints in different line?

Thanks in advance for your help.
# 2  
Old 11-08-2010
Try adding the -e switch to the echo command

Code:
do echo -e "Processing $each...\n";

# 3  
Old 11-08-2010
Hi toro95037, thanks for your reply.

It works adding -e option, the only thing is that it adds like a doble spacing like an
empty line, something like


Code:
this is my firts echo print...

this is my second echo print..

and not as I supposed.
Code:
this is my firts echo print...
this is my second echo print..

But in general terms is what I looking for.

Thanks again for your help
Smilie
# 4  
Old 11-08-2010
This is a feature of outlook - it's assuming any two lines that follow each other are part of the same paragraph so it joins them up. Best solution is to put a couple of spaces in the front of each line, this causes outlook to display them correctly.

eg:

Code:
echo "  Processing $each...\n";

# 5  
Old 11-09-2010
Hey Chubler_XL, how did you know that?Smilie

It was exactly how you said.Smilie

Really thanks, the echo print outs are now in different lines and closer between each other
.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script that will send an email if the cron job did not run.

Team, Would like to know what is the best script that will send you an email if cronjob did not run. Thanks (4 Replies)
Discussion started by: kenshinhimura
4 Replies

2. Shell Programming and Scripting

I want to send an email after cron job

I am using centos 6.4. I have a few cron jobs setup and they all work fine. However, I would like to enhance one of the crons. This is what I have at the moment: nice rsync -au /home/samba/wsaler/* /home/samba/wsaler.backup/wsaler.backup18pm date | /bin/mail -s "wsaler 3:00pm backup... (8 Replies)
Discussion started by: countrydj
8 Replies

3. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

4. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

5. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

6. Solaris

Solaris cron job email generation not required

Hi, How do we stop default cron job emails bein generated in Solaris 10? All our cron entries are ending with /dev/null 2>&1 but still emails are being generated. And all these emails are nuisance, as they are also get relayed to our local network sendmail MTA server (for system email... (14 Replies)
Discussion started by: hasan.kamali
14 Replies

7. UNIX for Advanced & Expert Users

cron job to extact lines from files to another file and ftp to new server

i have a text file in this format: which creates a new one everyday in the form of filename _zing__r200_2012_8_10_log.txt Fri Aug 10 07:29:17 EDT 2012, usera(192.168.0.245) to anotheruser: hey top, this is a private test Fri Aug 10 07:29:28 EDT 2012, anotheruser(192.168.0.245) to usera: got... (2 Replies)
Discussion started by: bkkid
2 Replies

8. Shell Programming and Scripting

how to avoid cron job output to send to the junk email folder?

Hi i created a cron job which invoke a shell script and output some content via email. Some times these output are sent to the junk email folder. i want these mails to be sent to inbox with some specific font. what i have to do? (4 Replies)
Discussion started by: vidhyaS
4 Replies

9. Shell Programming and Scripting

Cron Job Automated Email Alternatives?

Hi guys, not sure if this would be the right place for this but I dont where else it would go... I'm new to Unix too, so please bare with me :) I guess first up some background on the situation. We have some scripts that run as cron jobs which monitor and check the health, etc of our servers.... (2 Replies)
Discussion started by: BrianD
2 Replies

10. AIX

Cron Job notification email

Hi, I'm fairly new to Aix and am looking for some help on the following. I have setup a cron job under root and want it to send the email once it's run to an external email address. I can get it to send the output in an email to me by using mail on the end of the crontab entry. But I would... (1 Reply)
Discussion started by: elmesy
1 Replies
Login or Register to Ask a Question