Sending newly created log file from Suse to outlook mail

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…

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

[QUOTE=jmozdzen;28889]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[/QUOTE]


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

On 07/27/2015 11:04 PM, Santosh 2411 wrote:[color=blue]

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

}[/color]

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…

[QUOTE=ab;28897]On 07/27/2015 11:04 PM, Santosh 2411 wrote:[color=blue]

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

}[/color]

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…[/QUOTE]


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.

Hi Santosh,

instead its sending contents of it in mail

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

[QUOTE] [FONT=monospace][COLOR=#000000] [/COLOR][COLOR=#000000]-m, --mail [/COLOR][COLOR=#000000] [/COLOR]
Tells [COLOR=#000000]logrotate [/COLOR][COLOR=#000000]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 [/COLOR]
mail command is [COLOR=#000000]/bin/mail -s[/COLOR][COLOR=#000000].[/QUOTE][/COLOR]

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[/FONT]