format log file and send in email.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting format log file and send in email.
# 1  
Old 01-07-2011
format log file and send in email.

Hi guys i have one script which is as below

Code:
do 
some sqlplus output in to $LOG
sed '/^$/d' $LOG > /tmp/job.log
mv /tmp/job.log $LOG
awk '{if ($5=="COMPLETED") {print "backup completed at "$3" "$4 " of " $6 " for " d>> "/home/email.log" } else  {print "check backup for " d}}' d="$ORACLE_SID" $LOG
done
cat $EMAIL | mailx -s "STATUS" xxx@yyy.com
done

$EMAIL has output like below

Code:
backup completed at 06-JAN-2011 20:50:16 of DB for xx01q1
backup completed at 06-JAN-2011 21:01:24 of ARCHIVELOG for xx01q1
backup completed at 06-JAN-2011 21:26:36 of DB for xx02q1
backup completed at 06-JAN-2011 21:31:25 of ARCHIVELOG for xx02q1

and when it comes in email ..it comes like below ,,it comes like paragraph in 3 line.

Code:
backup completed at 06-JAN-2011 20:50:16 of DB for xx01q1 backup completed at 06-JAN-2011 21:01:24 of ARCHIVELOG for xx01q1 backup completed at 06-JAN-2011 21:26:36 of DB for xx02q1 backup completed at 06-JAN-2011 21:31:25 of ARCHIVELOG for xx02q1

I want the format like below both in EMAIL.log and outlook email.

Code:
backup completed at 06-JAN-2011 20:50:16 of  DB                                                             for xx01q1
backup completed at 06-JAN-2011 21:01:24 of  ARCHIVELOG  for xx01q1
backup completed at 06-JAN-2011 21:26:36 of  DB                                                             for xx02q1
backup completed at 06-JAN-2011 21:31:25 of  ARCHIVELOG  for xx02q1

please I need your help guys.

any command we can fix it so it comes very decent in outlook and both in file.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 01-07-2011 at 03:58 PM.. Reason: code tags, please!
# 2  
Old 01-07-2011
I came across similar problem in past and I appended another new line at the end of every line. That way your email file will look like:
Code:
backup completed at 06-JAN-2011 20:50:16 of DB for xx01q1
 
backup completed at 06-JAN-2011 21:01:24 of ARCHIVELOG for xx01q1
 
backup completed at 06-JAN-2011 21:26:36 of DB for xx02q1
 
backup completed at 06-JAN-2011 21:31:25 of ARCHIVELOG for xx02q1

And email body in outlook was as expected:
Code:
backup completed at 06-JAN-2011 20:50:16 of DB for xx01q1
backup completed at 06-JAN-2011 21:01:24 of ARCHIVELOG for xx01q1
backup completed at 06-JAN-2011 21:26:36 of DB for xx02q1
backup completed at 06-JAN-2011 21:31:25 of ARCHIVELOG for xx02q1


Last edited by anurag.singh; 01-07-2011 at 07:00 PM..
# 3  
Old 01-09-2011
Quote:
some sqlplus output in to $LOG
sed '/^$/d' $LOG > /tmp/job.log
mv /tmp/job.log $LOG
awk '{if ($5=="COMPLETED") {print "backup completed at "$3" "$4 " of " $6 " for " d>> "/home/email.log" } else {print "check backup for " d}}' d="$ORACLE_SID" $LOG
done
cat $EMAIL | mailx -s "STATUS" xxx@yyy.com
done
Stupid questions.
What is the value of "$EMAIL" ? What code generated that value?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send an email if "No such file or directory" in the shell script program log in EBS concur

Hi All, I have the below code(.sh) and need to send an email. #!/bin/bash cp /u02/xxc_incoming/TEST*.dat /u02/xxc_archive_incoming/AMER7764_ARPP_2/ cat /u02/xxc_incoming/TEST*.dat > /u02/xxc_incoming/XXC_TEST.dat rm /u02/xxc_incoming/TEST*.dat cd $XXC_TOP/bin sqlldr userid=apps/<pwd> ... (12 Replies)
Discussion started by: Mist123
12 Replies

2. Shell Programming and Scripting

Required to get out put of log in tabular format in email body

Dears Please support I have out put in text file and look like below fixed inquiries - Click on MAX suffix http://server:port/app User Details http://server:port/app Audit User Detail Action hhttp://server:port/app fixed inquiries - Click on MAX suffix http://server:port/app User Details ... (13 Replies)
Discussion started by: mirwasim
13 Replies

3. UNIX for Dummies Questions & Answers

Send Email To Windows OS Preserving The Format

I am trying to send an email using mailx and mutt commands with a body inside it. For some reason all the lines in the body are coming as one line, i figured it's not the issue with mailx/mutt but with line feed & carriage returns. So I tried adding carriage returns with below command based on... (13 Replies)
Discussion started by: Ariean
13 Replies

4. UNIX for Dummies Questions & Answers

send an email from batch file

My batch files run every day, it moves files from servers to my local computer, can I have a confirmation email sent to me from this batch file saying if the job failed or successes? Thank you for your help! (6 Replies)
Discussion started by: idiazza
6 Replies

5. Shell Programming and Scripting

Capture all error message in Log file and send the Log file by email

Hi I have a requirement to write a script to capture all errors in a Logfile and send the file in email. If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS. So I created a Log file and put the Appropriate... (2 Replies)
Discussion started by: dgmm
2 Replies

6. Cybersecurity

How can you send a file over Ip.NOT EMAIL

So I was just wondering... Is there a way to send a file directly to the computer..... Ive never gotten the answer and I want to know how, I keep running in to a wall :wall:. Why you may ask, well really for security reasons due to the fact that if this is done via a port I want to make sure to... (3 Replies)
Discussion started by: orszhak
3 Replies

7. UNIX for Advanced & Expert Users

How to send email as HTML format with attachment ?

hi.. Could somebody help me how to sent an attachment using sendmail command and the content is HTML format ?. Below is my code to sent the email as HTML but i do not know how to sent the attachment, please help me To: "BAHARIN HASAN"<baharin.hasan@gmail.com> from: "DATAONE SDN... (4 Replies)
Discussion started by: bh_hensem
4 Replies

8. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

9. Shell Programming and Scripting

parse the file and send email

Hi Experts, I am writing a script in which i want to parse the file and send the emails to some email-id's. The problem is like this-- I use to get some emails on saturday and sunday's but we do not work on these days. So what i want to do is forward those emails to some email id's. I want... (1 Reply)
Discussion started by: namishtiwari
1 Replies

10. Shell Programming and Scripting

script to send a file in email

a file is created on a daily basis in the name xyz_pqr_20071207.dat.i want to send the file as an attachment if the file contains more than 50 records.how can i write a script such that it will transmit the file after the file is created.i want to sed the file to say asdf@xyz.com. please help me... (2 Replies)
Discussion started by: dr46014
2 Replies
Login or Register to Ask a Question