Sending script output as email


 
Thread Tools Search this Thread
Operating Systems AIX Sending script output as email
# 1  
Old 07-26-2011
Sending script output as email

Hi
i have a script which executes daily through cron. The output of the script is appended to a log file everyday
It also emails me the output of the logfile as we have the mailx command in the script

The below is my requirement :

Normally When I get the email it sends the entire content in the log file. But I need only the script output content on the day it was executed.
To be more clear say for example if the script was executed on july 24th,25th and 26th. When i get the email on 24th it should send only the 24th log. Similarly when i get the email on 26th it should send only the 26th log.

How to do this ?
# 2  
Old 07-26-2011
If the log file contains date in fixed format , easily you can grep lines that contains the logged lines
# 3  
Old 07-26-2011
Instead of appending to the log file that you keep all daily output in. Direct your output to a daily log and email that to yourself. Then append the daily log into your historical log file by catting it into it. That way you have a daily log to meet your requirements and you have a historical log to go back every how many days you want.
# 4  
Old 07-26-2011
Use tee to accomplish this.

Code:
regular_command_here | tee -a /var/some_log_file | mailx to_who_you_want


Quote:
tee Command

Purpose

Displays the output of a program and copies it into a file.

Syntax

tee [ -a ] [ -i ] [ File ... ]

Description

The tee command reads standard input, then writes the output of a program to standard output and simultaneously copies it into the
specified file or files.

Flags

-a
Adds the output to the end of File instead of writing over it.
-i
Ignores interrupts.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending sql output to email body with conditional subject line

hi , i have written below piece of code to meet the requirement but i am stuck in the logic here. the requirement are: 1) to send the sql out put to email body with proper formatting. 2) if count_matching = Yes then mail should triggered with the subject line ... (10 Replies)
Discussion started by: itzkashi
10 Replies

2. Shell Programming and Scripting

Sending email in shell script

Can anyone help me out how to send the email without the word success while sending to the recipient. echo "success" | mailx -s "webshell instance has been started noiw" implementation@tkcl.com (8 Replies)
Discussion started by: ramkumar15
8 Replies

3. Shell Programming and Scripting

sending output of command via email

Hi all i want to send the output of a command by email, i have done this <comand> | mail -s <subject> <email address> which works well, but if the command retunrs noting then i just get a blank email, is there a way to stop this thanks Adam (4 Replies)
Discussion started by: ab52
4 Replies

4. Shell Programming and Scripting

Sending email from shell script

Hi, I need to send email from a shell script. i echoed some information to a file and i am doing cat command in the email syntax thanks (2 Replies)
Discussion started by: rocky1954
2 Replies

5. Shell Programming and Scripting

filtering and sending sar output via email

We have a program which create sar output files which has a weeks data... To read file we use sar -f sa15 command which has multiple days data( a weeks data)....we need to only get last 48 hours data and email it to different users.... I guess we can use combination of sar -o or even awk.... (3 Replies)
Discussion started by: noorm
3 Replies

6. Shell Programming and Scripting

sending email from a ksh script

hi all, i have a ksh script which is meant to send an email with an attachment. i use the following command to send email /usr/bin/uuencode $logFn $logFn | /usr/bin/mail -s "restoration results" $EMAILTO; where '$logFn' is the name of the file including the full path e.g... (0 Replies)
Discussion started by: cesarNZ
0 Replies

7. Shell Programming and Scripting

Running a shell script in cron...email not sending - help??

I am pretty new to Unix shell scripting, but wondered if anyone could help (in layman's terms if possible!!) :) I have a shell script which ultimately sends an alert to an email address if part of a batch of programs fails. Here's the script that sends the email: Script: 6check.csh... (8 Replies)
Discussion started by: tjhorwood
8 Replies

8. UNIX for Dummies Questions & Answers

Email sending through a shell script

Hi everyone, I have a shell script that I use to send some emails with attachments. Based on the attachment file that is being sent, I choose the recipient. My file_list.txt looks like this CAJ.txt;sm@email.com KXLD.txt;jc@email.com I do a grep on this file to look for the file name and... (3 Replies)
Discussion started by: memonks
3 Replies

9. Shell Programming and Scripting

Sending attachments using email through shell script

Hi all, I have written a shell script which sends emails with attachments to our clients. All our attachments are simple flat files (.txt format). The script is working fine and sending the attachments to the mail-ids except that, when i am sending the attachments to non-outlook users (Like... (6 Replies)
Discussion started by: symhonian
6 Replies

10. Shell Programming and Scripting

sending email from KSH unix script.

Hi Need guidance on including code to mail a couple of files atached with some subject and mail body !!.. Thanks in advance (3 Replies)
Discussion started by: rosh0623
3 Replies
Login or Register to Ask a Question