PDA

View Full Version : Sending newly created log file from Suse to outlook mail



Santosh_2411
27-Jul-2015, 09:38
Hello All,

I want to send newly created log file from suse linux to outlook mail box through command line.
In my machine I have configured logrotate for 5 days and I want to send logrotate’s latest output compressed file to outlook mail box every day at 00:30 (as logrotate rotate file at 00:00).
Below is the 5 days file output from my machine.

Server_Health_Logs-20150726.gz
Server_Health_Logs-20150727.gz
Server_Health_Logs-20150728.gz
Server_Health_Logs-20150729.gz
Server_Health_Logs-20150730.gz

From these above files I want to send only newly created (latest) file to outlook mail, like in this case I want to send Server_Health_Logs-20150730.gz.

Thanks in advance..

jmozdzen
27-Jul-2015, 16:52
Hi Santosh_2411,

> I want to send newly created log file from suse linux to outlook mail box through command line.
> In my machine I have configured logrotate for 5 days and I want to send logrotate’s latest output compressed file to outlook mail box every day at 00:30 (as logrotate rotate file at 00:00).

how about sending the rotated log via the post-rotate scripts instead? There'd be no delay and it would only occur when the logrotate job is (nearly) completed.

Regards,
Jens

Santosh_2411
28-Jul-2015, 06:00
Hi Santosh_2411,

> I want to send newly created log file from suse linux to outlook mail box through command line.
> In my machine I have configured logrotate for 5 days and I want to send logrotate’s latest output compressed file to outlook mail box every day at 00:30 (as logrotate rotate file at 00:00).

how about sending the rotated log via the post-rotate scripts instead? There'd be no delay and it would only occur when the logrotate job is (nearly) completed.

Regards,
Jens

**********************************************

Thanks Jens..

I have already used postroatate script but it's not sending log file as an attachment instead its sending contents of it in mail.
please find below script for the same:

/Server_Health_Logs
{
daily
mail ****@****.com
mailfirst
rotate 5
dateext
compress
create 777 root root

postrotate

T_FILE="${1}-$(date +%Y%m%d)"
mail -s "Test mail" -a Server_Health_Logs"${1}-$(date +%Y%m%d).gz" ****@****.com

endscript

}

Thanks and Regards,
Santosh Pande

ab
28-Jul-2015, 11:50
On 07/27/2015 11:04 PM, Santosh 2411 wrote:
>
> I have already used postroatate script but it's not sending log file as
> an attachment instead its sending contents of it in mail.
> please find below script for the same:
>
> /Server_Health_Logs
> {
> daily
> mail ****@****.com
> mailfirst
> rotate 5
> dateext
> compress
> create 777 root root
>
> postrotate
>
> T_FILE="${1}-$(date +%Y%m%d)"
> mail -s "Test mail" -a Server_Health_Logs"${1}-$(date +%Y%m%d).gz"
> ****@****.com
>
> endscript
>
> }

I do not know why, or how, this could put anything in the "contents" of
the mail message, unless you consider that everything in an e-mail message
(attachments or otherwise) is just part of contents of that message. This
should be a separate MIME component, and thus show up as an attachment.
I've used almost this exact command about a million times in the past
without any issues. Perhaps you need to send it some data for the message
body, so try this:



cat /dev/null | mail -s "Test mail" -a Server_Health_Logs"${1}-$(date
+%Y%m%d).gz" ****@****.com



--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

Santosh_2411
30-Jul-2015, 08:33
On 07/27/2015 11:04 PM, Santosh 2411 wrote:
>
> I have already used postroatate script but it's not sending log file as
> an attachment instead its sending contents of it in mail.
> please find below script for the same:
>
> /Server_Health_Logs
> {
> daily
> mail ****@****.com
> mailfirst
> rotate 5
> dateext
> compress
> create 777 root root
>
> postrotate
>
> T_FILE="${1}-$(date +%Y%m%d)"
> mail -s "Test mail" -a Server_Health_Logs"${1}-$(date +%Y%m%d).gz"
> ****@****.com
>
> endscript
>
> }

I do not know why, or how, this could put anything in the "contents" of
the mail message, unless you consider that everything in an e-mail message
(attachments or otherwise) is just part of contents of that message. This
should be a separate MIME component, and thus show up as an attachment.
I've used almost this exact command about a million times in the past
without any issues. Perhaps you need to send it some data for the message
body, so try this:



cat /dev/null | mail -s "Test mail" -a Server_Health_Logs"${1}-$(date
+%Y%m%d).gz" ****@****.com



--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

********************************************
Hello ab and jmozdzen,

ab,
i have tried your code too but its not working.
My same code is working on redhat but not in suse.
suse version is:
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 1

Below is my code.

/Server_Health_Logs
{
daily
rotate 5
dateext
compress
create 0600 root root

postrotate

mutt -s "Server Utilization Report" ****@******.com -a "${1}-$(date +%Y%m%d)"

endscript

}

Thanks and Regards.

jmozdzen
30-Jul-2015, 12:18
Hi Santosh,

> instead its sending contents of it in mail

this is likely caused by the "mail" and "mailfirst" parameters. From "man logrotate":


-m, --mail <command>
Tells logrotate which command to use when mailing logs. This command should accept two arguments: 1) the subject of the message, and 2) the recipient. The command must then read a message on standard input and mail it to the recipient. The default
mail command is /bin/mail -s.

You might want to verify that your postrotate script gets properly executed at all, or if you can detect multiple emails being sent (one by logrotate via "mail" handling, and one via the postrotate script).

Regards,
Jens